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
Post a Comment