Ganesh
Ganesh

Reputation: 1140

AngularJS using if statement with ng-repeat

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.

Upvotes: 2

Views: 312

Answers (3)

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>

Upvotes: 0

bamtheboozle
bamtheboozle

Reputation: 6406

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

Upvotes: 2

Aleksey Solovey
Aleksey Solovey

Reputation: 4191

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"

Upvotes: 0

Related Questions