AngularJs:NG-显示/ NG隐藏前pression未评估 [英] AngularJs: ng-show / ng-hide expression not evaluated

查看:89
本文介绍了AngularJs:NG-显示/ NG隐藏前pression未评估的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的JavaScript和AngularJS,不知道为什么在引号中的前pression没有评估?

I'm new to both javascript and AngularJS, and wondering why is the expression inside the quotes not evaluated?

<span ng-show="{{remaining()}}!==0">sometext</span>

这只不过是打印这样的:

it is simply printed like this:

<span ng-show="2!==0">sometext</span>

和NG-节目是不是不管内容合作。即使前pression被包裹在一个eval文本(和印刷前pression)所示,

and the ng-show is not working regardless of the contents. The text ( and the printed expression) is shown even if the expression is wrapped in an eval, :

eval("{{remaining()}}!==0")

我使出我的控制器为此创建一个函数:

I resorted to creating a function in my controller for this:

<span ng-show="renderOrNot()">sometext</span>

这工作,但我会preFER不要有我想要做一个比较,每次写一个函数

which works, but I would prefer not to have to write a function each time I want to make a comparison

推荐答案

几乎没有...

当您使用 {{}} ,该值是插入,即标记将被替换为前pression的结果。 ngShow预计只有前pression,因此就使用功能,因为它是,它可以工作:

When you use {{}}, the values are interpolated, i.e. the markup is replaced with the result of the expression. ngShow expects only the expression, so just use the function as it is, and it will work:

<span ng-show="remaining() !== 0">sometext</span>

在一般情况下,你只需要 {{}} 时,应显示你的前pression /内容。

In general, you'll only want {{ }} when your expression / content should be displayed.

这篇关于AngularJs:NG-显示/ NG隐藏前pression未评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆