我是新的角度指令。我在下面的指令混淆點點:
app.directive('person', function() {
return {
restrict: 'EA',
scope: {
header: '='
},
transclude:true,
link: function(scope, element, attrs, ctrl, transclude) {
scope.person = {
name: 'Directive Joe',
profession: 'Scope guy'
};
scope.header = 'Directive\'s header';
transclude(scope.$parent, function(clone, scope) {
element.append(clone);
});
}
};
});
HTML:在此指令scope
<body ng-controller="MainCtrl">
<person header="header">
<h2>{{header}}</h2>
<p>Hello, I am {{person.name}} and,</p>
<p>I am a {{person.profession}}</p>
</person>
</body>
用作隔離。那麼scope.$parent
代表transclude
函數。根據我的說法,如果scope
被隔離,那麼scope.$parent
代表$rootScope
。是嗎 ?請詳細解釋它。謝謝 !
[$ rootScope](https://docs.angularjs.org/api/ng/service/$rootScope)角度中的每個範圍都繼承它 – vil