【发布时间】:2014-10-05 02:17:04
【问题描述】:
基本上我希望能够访问我创建的指令的父范围,但我也希望能够访问我放置在元素上的属性。
例如相关的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}}
输出是“Hello”而不是“Hello Henry”
所以只是澄清一下,我想要做的就是访问属性和父范围。
【问题讨论】:
-
在你的directive.html中,你可以使用
{{$parent.name}}来访问属性name。但这是不合适的,因为它不会促进可重用性。
标签: javascript angularjs angular-directive