javascript - How do I add a custom condition in ng-if? -
i have pre-evaluated conditional statement used inside ng-if. this, in angular code:
scope.condition = "item.chosen == true"; ---(1)
i need use condition in ng-if condition, this:
<div ng-if="{{condition}}"></div> ---(2)
which ideally evaluated as
<div ng-if="item.chosen == true"></div> ---(3)
this of course doesn't work. clarify, cannot directly use code in 3 because mentioned scope.condition variable pre-evaluated , can't sure string value might be, except valid conditional statement.
how achieve this?
edit 1:
further clarification, condition variable need not item.chosen == true. item.count > limit or item.available == false. there no way know sure condition be, valid conditional statement in string format.
you can try this
<div ng-if="$eval(condition)"></div>
or
//view <div ng-if="condition"></div> //controller $scope.item.chosen = false; $scope.condition = $scope.$eval('item.chose == true')
Comments
Post a Comment