This question is based in the answer provided here
I want to output the result from a lodash
function applied to a scope ($scope.names
) when another scope ($scope.switch
) is set to true
, and to output the result of that lodash
function applied to a filtered
scope when $scope.switch
is set to false
.
So my ng-repeat
would be like this:
<ul>
<li ng-repeat="things in (filtered=(names | filter:filterType))">{{things}}</li>
</ul>
I use two ng-click
to change the state of $scope.switch and to apply/unapply the filter:
<a ng-click="switch = false; filterType=''">unswitch - No Filters</a><br><br>
<a ng-click="switch = true; filterType={name:'!Jimmy'}">switch - Not Jimmy</a>
And I used this code in order to watch the changes in $scope.switch
:
$scope.$watch('switch', function() {
$scope.thingScope =$scope.switch ? _.map($scope.names,"styles") : _.map($scope.filtered,"styles");
});
Here is the working plunkr with all the code (it's much easier to notice the problem here)
The problem is that the output of $scope.thingScope
doesn't correspond to the values showed in the ng-repeat
(right now every time I click, it shows the values of the previous one, that is, it goes one step behind). Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…