Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Directive can not find dependency injected

Here is my plunker - http://plnkr.co/edit/uqSB1gIz6XEmJfC8zHNb?p=preview

I am trying to inject Angular Strap

The index.html is including the right dependencies and in correct order

<script data-require="jquery@*" data-semver="2.0.1" src="http://code.jquery.com/jquery-2.0.1.min.js"></script>
<script data-require="[email protected]" data-semver="1.1.5" src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
<script data-require="[email protected]" data-semver="2.3.2" src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script data-require="[email protected]" data-semver="0.6.6" src="//cdnjs.cloudflare.com/ajax/libs/angular-strap/0.6.6/angular-strap.min.js"></script>

My console says

Error: Unknown provider: $strap.directivesProvider <- $strap.directives <- notificationDirective
@http://code.angularjs.org/1.1.5/angular.min.js:29
c@http://code.angularjs.org/1.1.5/angular.min.js:27
@http://code.angularjs.org/1.1.5/angular.min.js:30
c@http://code.angularjs.org/1.1.5/angular.min.js:27
d@http://code.angularjs.org/1.1.5/angular.min.js:27
@http://code.angularjs.org/1.1.5/angular.min.js:37
forEach@[native code]
like image 630
daydreamer Avatar asked Jan 27 '26 04:01

daydreamer


1 Answers

The module dependency for AngularStrap is listed in the wrong place. '$strap-directives' is a module dependency, not a service dependency, so it needs to be listed during the app bootstrap like:

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

It also needs to be removed as a service DI in your directive:

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

This is the way they configure the Plunkers on the AngularStrap site as well.

like image 64
Dan Avatar answered Jan 28 '26 18:01

Dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!