How to check undefined in AngularJS? -


can add check undefined value in ng-init.? if there value in scope print else print foobar. currently, should print foobar can add condition in ng-init ?

here code http://plnkr.co/edit/bfbawxq6dkdkxwaxp7v8?p=preview

  <body ng-controller="mainctrl" ng-init="test|| 'foobar'">     <p>hello {{test}}!</p>   </body> 

it's simple:

<body ng-controller="mainctrl" ng-init="test = test|| 'aasasas'">     <p>hello {{test}}!</p> </body> 

you can write write in javascript expression/line.

var app = angular.module('plunker', []);    app.controller('mainctrl', function($scope) {    });
<script data-require="angular.js@1.0.x" src="http://code.angularjs.org/1.2.0rc1/angular.js" data-semver="1.0.7"></script>  <div ng-app="plunker" ng-controller="mainctrl" ng-init="test = test|| 'aasasas'">    <p>hello {{test}}!</p>  </div>


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -