Angularjs 指令依赖于外部指令

标签 angularjs workflow directive

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

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

一系列 div 将根据参数添加到右侧、顶部或底部。

最佳答案

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

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

希望对你有帮助

关于Angularjs 指令依赖于外部指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18829869/

相关文章:

javascript - Angular 拼接隐藏错误

javascript - 如何使用 jQuery 为指令模板中的元素设置值

email - 使用 MS Dynamics Crm 2011 中的工作流创建电子邮件并动态填充 "To"字段

objective-c - 如何使用 c 型数组作为 ivar?

latex - 警告中的 tabularcolumns 指令未显示在 latex 中

angularjs - 移动应用程序如何在本地存储消息?

javascript - 为什么Angular.element常用而不需要注入(inject)?

javascript - 如何用 ng if 隐藏 ng Repeat

c# - 在贷款请求场景中推荐哪种工作流技术?

javascript - 与多个页面上的 div 同步内容