필자가 만든 지침의 부모 범위에 기본적으로 액세스 할 수 있기를 원하지만 요소에 배치 한 특성에 액세스 할 수 있기를 원합니다.부모 범위에 대한 액세스를 유지하면서 사용자 지정 지시문에서 요소 특성에 액세스하는 방법은 무엇입니까?
예를 들어관련 JS
app.directive('testDirective', function(){
return {
restrict:"E",
templateUrl:"directive.html",
scope:{
testAttribute: '='
}
};
});
app.controller('mainCtrl', function($scope){
$scope.name = 'henry'
}
index.html을
<div ng-controller="mainCtrl">
<test-directive test-attribute="Hello"></test-directive>
</div>
directive.html
{{testAttribute}}
{{name}}
출력이 "안녕하세요"대신
"안녕하세요 헨리"의입니다 그래서 명확하게 rify, 내가 할 수 있기를 원하는 것은 속성과 부모 범위에 액세스하는 것입니다.
directive.html에서 대신'{{$ parent.name}} '을 사용하여'name' 속성에 액세스 할 수 있습니다. 그러나 재사용을 촉진하지 않기 때문에 적절하지 않습니다. – ryeballar