2

I am new in angular, I want to check if condition like channel=='new' and wanna print "will be available asap"

<div ng-repeat="channel in channels">
        <label>
            <input type="checkbox"  ng-model="answer.content.args.channels[channel]"> {{channel}}
        </label>
    </div>

And i have tried to solve it using ng-if="channel == 'new'" , but it's not working for me.

2
  • inside the div: <label ng-if="channel === 'new'">Will be available asap</label><label ng-if="channel !== 'new'"> your checkbox</label>. The error in your ng-if is that you are assigning channel to 'new' (since you are using = while you need, instead, to compare it to a value. Commented Oct 19, 2017 at 14:42
  • You said you've tried using it but not shown how you tried it exactly? Can you show your actual attempt? Commented Oct 19, 2017 at 14:46

3 Answers 3

2

It's hard to understand what you're trying to do, but I'm assuming you want to show "will be available asap' if channel is new, and some other text other way. You can do that like so:

<input type="checkbox" ng-model="answer.content.args.channels[channel]"> {{channel === 'new' ? 'will be available asap' : 'some other text here'}} </input

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

Comments

0

There is a difference between an expression (what we check) and an assignment: a double/triple =. With assignment we set the value to be something, with expression we compare them.

You should change your expression to ng-if="channel == 'new'"

On top of that, ng-if is a lot slower than ng-show, so you might want to use that instead. Also if you have multiple conditions apart from 'new' (for example 'old'), you can use ng-switch and choose alternative choices with ng-switch-when="new"

Comments

0

Well you cant add inside of you div a <label> with a ng-if directive and type the next condition: ng-if="channel == 'new'". The code will looks like:

 <label ng-if="channel == 'new'"> will be available asap </label>

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.