Reputation: 51
Below is my html code
<div>IsValid : {{component._isValid || true}}</div>
If component._isValid
is undefined, it should show true but if it is defined, it should show its value. Currently it is showing true only.
Upvotes: 0
Views: 69
Reputation: 37
Use this code instead:
<div>IsValid : {{component._isValid ? component._isValid : true}}</div>
Upvotes: 0
Reputation: 354
The below line should do the needful. AngularJS directly identifies ternary operation in HTML.
<div>IsValid : {{typeof(component._isValid) === "undefined" ? true: component._isValid }}</div>
Upvotes: 0
Reputation: 3618
This is not a so simple condition, so you should better use a function in your controller:
isValid() {
return angular.isUndefined(component._isValid) ? true : component._isValid;
}
Call it in template with one-time binding if value is not changing:
<div>IsValid : {{ isValid() }}</div>
<div>IsValid : {{ ::isValid() }}</div>
Upvotes: 1