범위 매개 변수와 ng-controler가 모두있는 지시문을 만들려고합니다.scope와 ng-controller가있는 사용자 정의 angularjs 지시문
이이 지시어는 보는 방법이다 :
<csm-dir name="scopeParam" ng-controller="RegisteredController">
<!--Here I want to have content-->
{{name}}
</csm-dir>
나는 "RegistertedController는"내 응용 프로그램 어딘가에 선언했다.
angular.module('app')
.controller('RegisteredController', ['$scope', function ($scope) {
//$scope.name should be accessible here
}]);
그리고 지시를 선언하려고 :
angular.module('app')
.directive('csmDir', [function() {
return {
restrict: 'AE',
replace: true,
transclude: true,
scope: {
name: '='
},
template: '<section class="layout"><ng-transclude></ng-transclude></section>',
link: function (scope, element, attr, ctrl, transclude) {
element.find('ng-transclude').replaceWith(transclude());
//here I also need scope.name parameter
}
};
});
내가 얻을 오류 :
Multiple directives [ngController, csmDir] asking for new/isolated scope on: <csm-dir name="scopeParam" ng-controller="RegisteredController">
지금이 오류는 매우 유익, 나는대로 작동하지 않습니다는 각 취득 나는 여기에서 싶다.
지시어에서 "scope : {..}"매개 변수를 제거하고 컨트롤러에서 정의 할 수 있지만 필요한 것은 아닙니다.
기본적으로 ng-controller를 사용자 지정 지정 문에 제공 한 다음 해당 컨트롤러에 대한 추가 범위 변수를 제공해야합니다.
어떻게하면됩니까?
은 AngularJS 구성 요소로 충분하지 않습니까? – doge1ord