0

I'm trying to pass a dynamic query string into a directive that will filter the results that come back. So my code looks like this:

So say in my controller I have this:

var ctrlAs = this;
ctrlAs.location = "USA";

then in my html I have a directive:

<directive filter="location=ctrlAs.location">

THen in my directive i'm bringing in location like "=filter". I would expect the output in the directive to be "location=USA", but instead the output in the directive is just "USA".

Any suggestions on what i'm doing wrong?

2
  • 1
    try this filter="lctrlAs.location" Commented Apr 12, 2016 at 15:11
  • I realized my mistake right after I posted. I needed filter="'location=' + ctrlAs.location" Commented Apr 12, 2016 at 15:14

1 Answer 1

1

try like this.

OR change directive template like this

   template : '<div><span><label>location=</label>{{filter}}</span></div>'

var myApp = angular.module('MyApp',[])
myApp.directive('directive', function() {
    return {
        restrict: 'E',
        replace: true,
        scope: {
            filter: '='
        },
        template : '<div><span>{{filter}}</span></div>',

      controller: function($scope, $element, $attrs, $location) {        
      }
    }
});
      

myApp.controller('MyController', function($scope, $window) {
    $scope.location = 'USA';
   
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="MyApp">
    <div ng-controller="MyController">
        <directive  filter="'location='+location"  />
    </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.