1

I'm trying to compare a string value inside ng-if but it doesn't work properly.

For example, i have this scope value to be compared with a string:

vm.val = 'abc'; //or vm.myval = 'afg';

And the html looks like this:

<div ng-if="vm.myval == 'abc'> Option abc </div>
<div ng-if="vm.myval == 'afg'> Option afg </div>

But the output is always the first option, Option abc. I even tried using === but the result is the same.

How can I compare this to an exact match of the strings?

1
  • is the controlleras = vm? Commented Apr 19, 2016 at 15:05

1 Answer 1

3

If everything else is alright, you just forgot to close the quotes, try:

<div ng-if="vm.myval == 'abc'"> Option abc </div>
<div ng-if="vm.myval == 'afg'"> Option afg </div>
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.