Reputation: 8663
I'm familiar with using ng-show and ng-hide when my bound data contains a specific word or piece of text. For example:
<div ng-show="myArray.Length > 20">
Show something
</div>
<div ng-show="myData.Name == 'Harry Roberts'">
Show something
</div>
However, how can i use ng-show
to show when the bound data contains a certain value, for example, 'Current'. For example, if my JSON data:
{
"MyAddresses": [
{
"Entry" : "1",
"Period" : "2011 - current",
}, {
"Entry" : "2",
"Period" : "2003 - 2011",
}, {
"Entry" : "3",
"Period" : "1998 - 2001",
}
]
}
<div ng-show="myData.MyAddresses.Period ~ 'Current'">
Show something
</div>
Upvotes: 6
Views: 10071
Reputation: 187
Below code works for me to check the substring
<div ng-show = "address.indexOf('expected string')!=-1">
Show something
</div>
Upvotes: 3
Reputation: 4022
Use the function indexOf
to search for a substring in a string. It will return the position of the search string if found or will return -1.
So you can use an expression like myData.MyAddresses.Period.indexOf('Current') != -1
to show/hide data
Upvotes: 12