javascript - How to render angularjs content conditional? -
i want render ui content in frontend, based on boolean state of controller variable.
controller:
$scope.test = [ myvar = true //some other variables , data ]; html:
<div ng-controller"mycontroller"> <p>'{{test}}'</p> <p>'{{test.myvar}}'</p> <p ng-if="{{test.myvar}}">show content</p> </div> result:
'[true]' '' the 2nd statement somehow not rendered. why?
[] literal arrays, not have string keys.
= assigns variable, it's not used associating keys , values.
you want object literal, looks this:
$scope.test = { myvar: true }; you've messed syntax in directive:
<p ng-if="test.myvar">show content</p> {{}} not necessary in directives; content of directive attribute parsed inside directive, not need bound. {{}} pretty necessary "echoing" data.
Comments
Post a Comment