Angularjs指令依赖于外部指令

时间:2013-09-16 13:57:27

标签: angularjs workflow directive

我需要在Angularjs中开发工作流编辑器

这需要一个指令(内部),它应该添加一个带有一些数据的div,这个指令的数据应来自另一个指令(外部)

系列div将根据参数右,上或下添加。

1 个答案:

答案 0 :(得分:3)

由于您没有发布任何代码或确切要求,请查看此演示,其中显示来自其他指令的调用指令:

<强> HTML

<div ng-controller="MyCtrl">
  <div directive-foo></div>

<强> JS

var app = angular.module('myApp',[]);

app.directive('directiveFoo', function() {
return {
    template: '<div directive-bar="123">bar</div>',
    replace: true,
    controller: function() {
        console.log('in foo ctrl');
        this.isFooAlive = function() {
            return 'Foo is alive and well';
        }
    }
}
});
app.directive('directiveBar', function() {
return {
    controller: function() {
        console.log('in bar ctrl');
    },
    require: 'directiveFoo',
    link: function(scope, element, attrs, fooCtrl) {
        console.log(fooCtrl.isFooAlive());
    }
}
});

function MyCtrl($scope) {
}

FIDDLE DEMO

希望它能帮到你

相关问题