2

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. What is wrong with my ng-if condition?

<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>
2
  • 2
    Remove the {{/}}, ng-if takes an expression, not an interpolated value. Commented Jun 5, 2015 at 21:10
  • @NikosParaskevopoulos You should submit that as the answer perhaps with a slightly more descriptive explanation. Commented Jun 5, 2015 at 21:12

1 Answer 1

3

As mentioned, ngIf takes an expression.

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

See the AngularJS expression docs for more information on what this entails exactly. 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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.