2017-12-28 11 views
1

안녕 내가 버튼을 해제해야 할 것은 내 코드입니다 :얻기 콘솔 오류

<button" ng-disabled="scenariosViewAll.isSetDisable(scenariosViewAll.collectionBookObject)">Create Book from Collection</button> 

및 컨트롤러 내 코드 :

function isSetDisable(obj) { 
      return typeof(obj === 'Object') && Object.keys(obj).length === 0 ? true : false; 
     } 

아래와 같이 콘솔 오류가 발생하고 코드가 올바르게 작동하고 있습니다.

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 
+0

'대해서 typeof (OBJ === '객체')'항상'truthy은 "부울"'리턴 – Andreas

+0

@Andreas 다음 ['typeof' __operator __]에 설명서를 확인 –

+1

솔루션 (무엇인가 – Andreas

답변

0
function isSetDisable(obj) { 
      return typeof(obj) === 'object' && Object.keys(obj).length === 0 ? true : false; 
     } 
+0

정말 고마워요. –

1

당신은 Object 조건을 변경 가능 null 값을 처리하기 위해 추가 조건을 추가한다

function isSetDisable(obj) { 
      return obj != null && typeof(obj) == typeof({}) && Object.keys(obj).length === 0 ? true : false; 
     }