简体   繁体   English

角ng-if用于检查空字符串不起作用

[英]Angular ng-if for checking empty string not working

In my view, I have the below code to display some data from angular scope variables. 在我看来,我有以下代码来显示角度范围变量的一些数据。 The first two lines work fine. 前两行工作正常。 They display data from the scope variables but the line from ng-if does not display. 它们显示范围变量中的数据,但不显示ng-if中的行。 What is wrong with my ng-if condition? 我的ng-if条件有什么问题?

<div ng-controller="PaymentCtrl">

    <h3>Payment successfully posted {{PaymentID}}</h3>

    <h3> Receipt number {{ReceiptNumber}} </h3>

    <div ng-if="{{ReceiptNumber}}">
        <h3>Receipt generated with receipt number {{ReceiptNumber}}</h3>
    </div>

</div>

As mentioned, ngIf takes an expression. 如前所述, ngIf接受一个表达式。

<ANY ng-if="expression"> ... <ANY>

See the AngularJS expression docs for more information on what this entails exactly. 有关确切含义的更多信息,请参见AngularJS表达式文档 In your example, you are instead supplying an interpolated value . 在您的示例中,您提供的是内插值 Try the following... 尝试以下...

<div ng-if="ReceiptNumber">
    <h3>Receipt generated with receipt number {{ReceiptNumber}}</h3>
</div>

JSFiddle Link - demo comparing both wrong and correct appreach JSFiddle Link-演示比较错误和正确的应用范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM