这个问题在这里已经有了答案:
Checking if a key exists in a JavaScript object?
(25 个回答)
7年前关闭。
如何在 AngularJS 中检查对象是否具有某个属性?
最佳答案
You could use 'hasOwnProperty' to check if object have the specific property.
if($scope.test.hasOwnProperty('bye')){
// do this
}else{
// do this then
}
这是一个 demo在 jsFiddle 中。
希望这有帮助。
关于angularjs - 检查对象是否具有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20464807/