从其他模块访问指令

Gya*_*raw 1 dependency-injection angularjs angular-directive angular-controller

我有两个不同的模块,第一个包含控制器的第二个指令。

基本上,我希望directive在我的渲染view。但是,随着modulesdirectivecontroller是不同的,它给错误。

如果我给的相同,module那么我希望为所有控制器提供服务的通用模块可以解决我的问题。

controller

angular.module('SlamModuleCtrl')
        .controller('SlambookExt',['$scope','$route','SlambookCollection', function($scope,$route) {
            console.log("slam controller")
        }]);
Run Code Online (Sandbox Code Playgroud)

Directive

angular.module('Genericmodule')
    .directive('appVersion', ['version', function (version) {
       return {
    restrict: 'E',  
    template: '<h1>version1</h1>'
    } 
    }])
Run Code Online (Sandbox Code Playgroud)

View

 <div ng-controller="SlambookExt">
     <app-version>1</app-version>
    </div>
Run Code Online (Sandbox Code Playgroud)

Cha*_*thu 5

实例化时slamModuleCtrl,需要指定genericModule为依赖项。

或使用将这两个模块都作为依赖项加载的父模块,然后将该父模块用作您的ng-app

angular.module('parentModule',['slamModuleCtrl','genericModue'])

这只是一个可行的解决方案,因为您的两个模块对我而言都是正确的。因此,我猜测该版本未显示,因为尚未加载该模块