[英]Getting console error for object return
Hi i have to disable button if i get scenariosViewAll.collectionBookObject ={} array ,For this i am using function to return below is my code:嗨,我必须禁用按钮,如果我得到 scriptsViewAll.collectionBookObject ={} 数组,为此我使用函数返回下面是我的代码:
<button" ng-disabled="scenariosViewAll.isSetDisable(scenariosViewAll.collectionBookObject)">Create Book from Collection</button>
and in controller my code is:在控制器中我的代码是:
function isSetDisable(obj) {
return typeof(obj === 'Object') && Object.keys(obj).length === 0 ? true : false;
}
getting console error as below and it is working properly, any wrong in my code.收到如下控制台错误并且它工作正常,我的代码中有任何错误。
lib.min.js:3762 TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at scenariosViewAllController.isSetDisable (app.min.js:29729)
at fn (eval at compile (lib.min.js:3876), <anonymous>:4:415)
at m.$digest (lib.min.js:3787)
at m.$apply (lib.min.js:3790)
at lib.min.js:3803
at e (lib.min.js:3690)
at lib.min.js:3693
You should change Object
condition and add extra condition to handle possible null
values;您应该更改Object
条件并添加额外的条件来处理可能的null
值;
function isSetDisable(obj) {
return obj != null && typeof(obj) == typeof({}) && Object.keys(obj).length === 0 ? true : false;
}
function isSetDisable(obj) {
return typeof(obj) === 'object' && Object.keys(obj).length === 0 ? true : false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.