我想分享以下兩個指令之間的$scope
:如何在AngularJS中的兩個指令之間共享範圍?
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>
我已經創建了一個名爲「指令1」與隔離範圍的指令,分配名稱「表」到scope.tablename
屬性。我無法在其他指令中訪問此範圍屬性。
那麼我怎樣才能訪問另一個指令的範圍?
如何在HTML中被組織的指示? – Chandermani
@chnadermani我已更新我的問題,我已對不同元素應用指令。 – Shivkumar