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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -