2014-04-26 5 views
6

어떻게 다음과 같은 속성으로 전달 된 필드와 함께 각 범위를 사용자 정의 필드를 추가 할 수 있습니다AngularJS와 사용자 정의 지시 고립 범위 사용자 정의 필드

angular.module('app') 
    .directive("myDirective", function(){ 
     function NewObj() 
     { 
      this.id = 0; 
      this.name = ""; 
     } 
     return{ 
      restrict: "E", 
      templateUrl:"partials/directives/temp.html", 
      scope:{ 
        viewId:"=", 
        dataObj: new NewObj() //This is the custom obj 
        } 

      } 
     } 

내가 그래서, 내가 잘못된 고립 범위를 얻을 않는 경우 정의. 어떻게이 작업을 수행 할 수 있습니까?

+0

: 당신은 뭔가를 시도 할 수 있습니다, 당신이 원하는 것을 할 수 http://umur.io/angularjs-directives-using-isolated-scope-with-attributes/ –

답변

5

지시어의 범위는 '=', '&', '@'중 하나 일 수 있습니다. 다음 지침 범위에 대한 알맞은 설명이있어

angular.module('app') 
.directive("myDirective", function() { 
    function NewObj() { 
     id = 0; 
     this.name = ""; 
    } 
    return { 
     restrict: "E", 
     templateUrl:"partials/directives/temp.html", 
     scope: { 
      viewId:"=",      
     }, 
     controller: ['$scope', function($scope) { 
      $scope.dataObj = new NewObj(); 
     }] 
    }; 
}); 
+0

불행히도, 이것은 여러 지시어에 대해 동일한 컨트롤러 (범위 내에서 전달 된 다른 매개 변수로)를 재사용하지 못하게합니다. –