javascript - AngularJS ng-repeat filter works when hardcoded but not when passed as controller variable -
so want make drop down menu changes filter value of ng-repeat this:
<div ng-repeat="{{filter}}">
so have line in controller right hard-coded
$scope.filter = 'lang in langs | filter:{type:\'interpreted\'}';
and can verify {{filter}} spit out string, ng-repeat doesn't work when given string double bracket variable, when it's hard-coded in. can not pass angular controller variables other angular functions ng-repeat?
why not inject $filter
service controller , filtering there. can filter langs in controller so:
$scope.filteredlangs = $filter('filter')($scope.langs, {type:'interpreted'});
then can repeat filtered langs via ngrepeat
directive:
<div ng-repeat="lang in filteredlangs">
remember, ngrepeat
directive evaluates expression not need curly braces have in example.
if looking change type in filter update variable in controller:
$scope.mytype = "interpreted";
in view:
<div ng-repeat="lang in langs | filter: {type: mytype}">
Comments
Post a Comment