템플릿의 인스턴스입니까? 뭐? 템플릿은 단순한 문자열이며 그게 전부입니다. 컨트롤러 정보 : 각도 요소 컨트롤러로 DOM 요소를 관리 할 수 있습니다. 지시어가 DOM 요소에 적용되고 있습니다. 그런 다음 컨트롤러도 사용할 수 있습니다. 지시기 컨트롤러를 간단히 설명하면 다음과 같습니다.
// directive with name parentDirective
{
link: function() { ... },
restrict: 'A',
controller: [ '$scope', function ($scope) {
this.sayHello = function() { alert('hello'); }
// 'this' references the instance of the directive controller and then can be required by a child
}],
template: '<div><child-directive/></div>'
}
// child directive with the name childDirective
{
require: '^parentDirective',
link: function (scope, $element, attributes, parentDirectiveController) {
parentDirectiveController.sayHello();
}
}
템플릿 안의 요소를 찾고 컨트롤러()를 호출 할 수 있습니다. –
감사합니다 @WalterBrand, 유일한 방법 인 것 같습니다. 부끄러운 일은 DOM에 액세스하는 것입니다. –