2014-09-18 2 views
0

서버에서 Json을로드하고 "sign_change_global"값이 있으면 HTML에 다른 내용이 표시됩니다. 그래서 이것은 HTML 문제 일뿐, 컨트롤러에 추가 할 부분이 있습니까?특정 값이 목록의 내용인지 확인하는 방법

JSON :

[ 
    "pb_edit", 
    "pb_import_execute", 
    "role_edit", 
    "sign_change_global", 
    "sign_change_own", 
    "sign_deactivate" 
] 

JS :

var getAccountPermission = function() { 
     if (AuthService.isAuth()) { 
     // check only when authenticated (or refresh possible) 
     AccountPermissions.one().get().then(
      function (resultOk) { 
       $log.d("AccountPermissions ok: ", resultOk); 
       $scope.permissions= resultOk.data; 
      }, 
      function (resultError) { 
       $log.d("Accountinfo error: ", resultError); 
       ErrorService.showApiError(resultError); 
      }, 
      function (resultNotify) { 
       $log.d("Accountinfo notify:", resultNotify); 
      } 
     ); 
     } 
    }; 

    getAccountPermission(); 

HTML : 당신이 확인하는 경우 내 생각

<div ng-show="permissions.sign_change_global"> 
    <i> Show this, when "sign_change_global" is in LIST</i><br/> 
    <textarea rows="5" cols="40" ng-model="newCustomerSig" ng-trim="false" placeholder="{{user.customer.signature}}"></textarea> 
</div> 

답변

1

경우 목록의 공동 ntains 요소는 당신이 array.indexOf(element) != -1

$scope.permissionExists(permission){ 
    if(elementName == undefined){ 
      return false; 
    }else{ 
      return $scope.permissions.indexOf(permission) != -1; 
    } 
} 

및 마크 업에 내가 약간 JS 코드를 편집 해

<div ng-show="permissionExists('sign_change_global')"> 
    <i> Show this, when "sign_change_global" is in LIST</i><br/> 
    <textarea rows="5" cols="40" ng-model="newCustomerSig" ng-trim="false" placeholder="{{user.customer.signature}}"></textarea> 
</div> 
+0

만이 사용할 수 있습니다 list.so 점에서 요소가 존재하는지 여부를 확인하는 함수를 사용해야합니다 잘 작동합니다! 고맙습니다 – Flowdo

관련 문제