相关疑难解决方法(0)

angular.js中的内联条件

我想知道是否有一种角度有条件地显示内容而不是使用ng-show等.例如在backbone.js我可以在模板中使用内联内容做一些事情,如:

<% if (myVar === "two") { %> show this<% } %>
Run Code Online (Sandbox Code Playgroud)

但在角度方面,我似乎仅限于显示和隐藏包含在html标签中的内容

<p ng-hide="true">I'm hidden</p>
<p ng-show="true">I'm shown</p>
Run Code Online (Sandbox Code Playgroud)

如果使用{{}}而不是将内容包装在html标记中,有条件地以角度显示和隐藏内嵌内容的角度建议方法是什么?

if-statement ternary-operator angularjs

190
推荐指数
5
解决办法
28万
查看次数

angularjs是否作为$ scope.null处理null?

问题的例子

<div ng-show="bar !== null">hello</div>
Run Code Online (Sandbox Code Playgroud)

这是否在范围内评估为

$scope.bar !== null
Run Code Online (Sandbox Code Playgroud)

还是这样?

$scope.bar !== $scope.null
Run Code Online (Sandbox Code Playgroud)

请注意,在最后一种情况下,$ scope.null将是未定义的,并且示例似乎正常工作.

奖金:

如果bar = null则会发生这种情况

// this does not work (shows hello)
<div ng-show="bar !== null">hello</div>
Run Code Online (Sandbox Code Playgroud)

没有给出相同的结果

// this works ok (does not show hello)
<div ng-show="bar != null">hello</div>
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

angularjs angularjs-scope

4
推荐指数
1
解决办法
618
查看次数