2013-08-22 5 views
0

컨트롤러의 메서드를 내 지시문에 전달하려고합니다. 컨트롤러에서AngularJS 지시문 : 분리 된 범위의 '&'가 예상대로 작동하지 않습니다.

: 이것은 내가 그 일을하고있어 어떻게보기/HTML에서

$scope.getEmployees = function() 
{ 
    return {2: 'Jane', 3: 'Bob', 4: 'Smith'}; 
} 

$scope.getSelected = function() 
{ 
    return 3; 
} 

:

<mydirective data-placeHolder="Choose an employee.." 
     data-getOpts="getEmployees()" data-getSelected="getSelected()" /> 

이 지침에서 :

var dir = 
{ 
    restrict: 'E', 
    templateUrl : 'views/mydirective.html', 
    scope: { 
     placeholder: '@', 
     getSelected: '&', 
     getOpts: '&' 
    }, 
    controller: ['$scope', '$element', '$attrs', 
     function($scope, $element, $attrs) 
     { 
      console.log($scope.getOpts()); 
     }], 

}; 

MyApp.directive('mydirective', function() 
{ 
    return dir; 
}); 

그러나, 지시어의 컨트롤러에있는 다음 줄 :

console.log($scope.getOpts()); 

컨트롤러의 getEmployees() 기능에서 설정된 개체 또는 기능을 반환하지 않고 정의되지 않은 값을 생성합니다.

내가 뭘 잘못하고 있니?

답변

2

명명 규칙과 관련이 있습니다. 이처럼 낙타의 경우 대시로 구분 된 단어로 변환해야합니다.

data-get-opts="getEmployees()" 
+0

@ClickUpvote LOL. 나는 그 비디오를 좋아한다. .. 용의 공은 흔들어 움직인다! – zsong

관련 문제