YoroDiallo YoroDiallo - 3 months ago 12
AngularJS Question

check param in object in ng-model

I have list with some persons, and if this person have comment field - you can edit this information in

input:text
. So I show this field when person have this field. But I have a problem, when I remove previous comment - input is hide. It's couse
person.comment = ""
, and I think it meens like false.

<input person="text" ng-show='person.comment' ng-model='person.comment'>


i try to do this thing:

ng-show='person.comment || person.comment === ""'


but perhaps exist a different way? like
comment in person
? My plnkr.

Answer

To check if an object has a key in javascript, for you, you could write:

ng-show="person.hasOwnProperty('comment')"

from how do i check if an object has a key in javascript?