我无法搞清楚如何有一个指令一个指令不同的内触发事件指令可与其他指令沟通
说我有以下2个指令
project.directive('ActionButton', function() {
return {
restrict: 'E',
scope: {
orderId: '@'
},
templateUrl: '/scripts/templates/directive-templates/order-action-button.html',
link: function (scope, element, attrs) {
scope.doAction = function() {
// I want to trigger 'scope.refreshOrderDetails' in my other directive from here
}
}
}
project.directive('OrderView', function() {
return {
restrict: 'E',
scope: {
orderId: '@'
},
templateUrl: '/scripts/templates/directive-templates/order-view.html',
link: function (scope, element, attrs) {
scope.refreshOrderDetails = function() {
// data is refreshed here
}
}
}
,而且我用我的指令,这样
<ca-action-button order-id="{{orderId}}"></ca-order-action-button>
<ca-order-view order-id="{{orderId}}"></ca-order-details>
其中CA-订单细节开始用数据填充,但是当CA阶动作按钮触发事件需要刷新。
动作按钮将被加载许多doAction(它是一个按钮下拉多动作),并且会有一些不同的OrderView类型指令,每个指令都有自己的一组数据需要刷新不同的触发器
好像你需要使用一个父控制器为这两个指令通过,而不是使用事件(这可以得到笨拙,尤其是当你拥有多套指令的页面上) – Adam 2015-04-02 14:13:37