2013-05-29 28 views
1

这里是我的plunker - http://plnkr.co/edit/uqSB1gIz6XEmJfC8zHNb?p=previewAngularJS:指令无法找到的依赖注入

我试图注入Angular Strap

index.html是包括右依赖和以正确的顺序

By Console says

Error: Unknown provider: $strap.directivesProvider <- $strap.directives <- notificationDirective 
@http://code.angularjs.org/1.1.5/angular.min.js:29 
[email protected]://code.angularjs.org/1.1.5/angular.min.js:27 
@http://code.angularjs.org/1.1.5/angular.min.js:30 
[email protected]://code.angularjs.org/1.1.5/angular.min.js:27 
[email protected]://code.angularjs.org/1.1.5/angular.min.js:27 
@http://code.angularjs.org/1.1.5/angular.min.js:37 
[email protected][native code] 

回答

3

AngularStrap的模块依赖项列在错误的地方。 '$strap-directives'是一个模块的依赖性,而不是服务的依赖,所以它需要像应用引导期间上市:

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

还需要在您的指导服务DI被删除:

app.directive('notification', function(){ 
    return { 
     restrict: 'E', 
     replace: true, 
     scope: { 
      ngModel: '=' 
     }, 
     template: '<div>Test</div>' 
    } 
}); 

这也是他们在AngularStrap site上配置Plunkers的方式。

1

$strap.directives是一个模块。您需要将其定义为您自己的模块的依赖项:

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

您不需要将此注入到指令中。因此,您的指令只会看起来像:

app.directive('notification', function(){ 
    return { 
    restrict: 'E', 
    replace: true, 
    scope: { 
     ngModel: '=' 
    }, 
    template: '<div>Test</div>' 
    } 
}); 
+1

这将抛出一个错误,因为该指令试图注入'strap'失败 – sh0ber

+0

啊是的!编辑我的帖子。非常感谢! – callmekatootie