如何在将范围变量传递给ng-show之前对其进行评估

时间:2014-03-11 21:00:05

标签: javascript angularjs

控制器

scope.x = 'y';
scope.y = true;

模板

<div ng-show="{{x}}"></div>

结果应该是一个可见的div,但它隐藏了

但html显示了我的期望

<div ng-show="y"></div>

我的实际更复杂的例子我得到了这个错误

TypeError: Cannot read property 'exp' of undefined
    at watchFnToHumanReadableString (<anonymous>:703:19)
    ...

this plunkr show the simple example

1 个答案:

答案 0 :(得分:2)

要评估范围变量,您需要从$ scope调用$ eval函数。

您的代码应如下所示:

<body ng-controller="MainCtrl">
<p ng-show="$eval(x)">Hello {{name}}!</p>
</body>
相关问题