$scope
次の 2 つのディレクティブ間で共有したい:
One23SRCApp.directive('directive1',function() {
return {
restrict: "A",
scope:true,
link: function (scope, element, attrs) {
scope.tablename = "table";
}
};
});
One23SRCApp.directive('directive2',function() {
return {
restrict: "A",
link: function (scope, element, attrs) {
var tablename = scope.tablename;
}
};
})
HTMLには、次のものがあります。
<input type="text" directive2 placeholder="Search Models...">
<table directive1>
<tr>
<td>column1</td>
<td>column1</td>
</tr>
</table>
「directive1」という名前のディレクティブを分離スコープで作成し、「table」という名前をscope.tablename
プロパティに割り当てました。他のディレクティブでこのスコープ プロパティにアクセスできません。
では、あるディレクティブのスコープに別のディレクティブでアクセスするにはどうすればよいでしょうか?