Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查AngularJS中的未定义?_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

如何检查AngularJS中的未定义?

如何检查AngularJS中的未定义?,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,我们可以在ng init中添加checkundefined值吗。?如果范围中有值,则打印它,否则打印foobar。目前,它应该打印foobar 我们可以在ng init中添加一个条件吗 这是我的密码 你好{{test}} 就这么简单: <body ng-controller="MainCtrl" ng-init="test = test|| 'aasasas'"> <p>Hello {{test}}!</p> </body> 你好{

我们可以在
ng init
中添加check
undefined
值吗。?如果范围中有值,则打印它,否则打印
foobar
。目前,它应该打印
foobar
我们可以在
ng init
中添加一个条件吗

这是我的密码


你好{{test}}

就这么简单:

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

你好{{test}}


是您可以在
ng init

<body ng-controller="MainCtrl" ng-init="test = test ? test: 'aasasas'">
 <p>Hello {{test}}!</p>
</body>

你好{{test}}

test
的值将是
test
本身(如果已定义),否则“aasaas”将使用基本JavaScript语法-
<body ng-controller="MainCtrl" ng-init="test = test ? test: 'aasasas'">
 <p>Hello {{test}}!</p>
</body>