error when assigning a controller in the directive?

381 views
Skip to first unread message

yahya Kacem

unread,
Feb 6, 2013, 3:01:49 PM2/6/13
to ang...@googlegroups.com
Hi, how to correctly assign a controller to a directive so 2 directives can communicate to each other. When I set the require argument of the second directive to the name of the first directive i get an error in the console:

  1. Error: No controller: dir at Error (<anonymous>) at getControllers (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:4132:19) at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:4259:35) at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:3869:15) at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:3872:13) at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:4252:24) at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:3869:15) at compositeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:3872:13) at publicLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:3775:30) at http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js:934:25 <div class="btn btn-danger" dir2=""> angular.js:5601
    1. (anonymous function)angular.js:5601
    2. (anonymous function)angular.js:4698
    3. nodeLinkFnangular.js:4261
    4. compositeLinkFnangular.js:3869
    5. compositeLinkFnangular.js:3872
    6. nodeLinkFnangular.js:4252
    7. compositeLinkFnangular.js:3869
    8. compositeLinkFnangular.js:3872
    9. publicLinkFnangular.js:3775
    10. (anonymous function)angular.js:934
    11. Scope.$evalangular.js:7905
    12. Scope.$applyangular.js:7985
    13. (anonymous function)angular.js:932
    14. angularInitangular.js:906
    15. (anonymous function)angular.js:14600
    16. H


here's a plnkr with an example code.
Thanks in advance.

Pawel Kozlowski

unread,
Feb 6, 2013, 3:04:57 PM2/6/13
to ang...@googlegroups.com
Hi!

You need to use require: "dir".

You can have a look at tabs directive from the bootstrap repo for an
example of 2 directives communicating together:
https://github.com/angular-ui/bootstrap/blob/master/src/tabs/tabs.js

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+u...@googlegroups.com.
> To post to this group, send email to ang...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Looking for bootstrap-based widget library for AngularJS?
http://angular-ui.github.com/bootstrap/
Message has been deleted

yahya Kacem

unread,
Feb 7, 2013, 3:37:29 AM2/7/13
to ang...@googlegroups.com
Hi, and thanks for replaying, i'm using require: dir, i just forget to put it in the example now it's there, and the same error still appears, the code is written exactly like in the documentation said it should be written, am I doing something wrong or what.

Thanks in advance.

Mark Perry

unread,
Feb 7, 2013, 6:23:00 AM2/7/13
to ang...@googlegroups.com
To share a controller between directives you need to nest the sub directives inside the parent one.

For example:

<div parentDirective>
    <span subDirective>Something</span>
</div>

Now "subDirective" can use the controller from "parentDirective" due to the inheritance from $scope.

At least this is what I have found.

Thanks, Mark

yahya Kacem

unread,
Feb 7, 2013, 12:58:44 PM2/7/13
to ang...@googlegroups.com
Thank you that did it.
Reply all
Reply to author
Forward
0 new messages