-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Error when controller is specified at the same level of directive #8043
Comments
The main issue here is that isolate scope properties are not "ready" at the time of controller instantiation, they're actually ready shortly after that. Something like this will usually work better for you: http://plnkr.co/edit/bCniFefoBkHnhRTYvk3q?p=preview (My PR to allow isolate scope bindings directly into the controller will probably make this easier for people too) |
@caitp, when you say 'the isolate scope properties are not "ready"', is this because controllers are called before the preLink phase where binding occurs? The following code suggests that controller do get the isolated scope alright:
|
I never said they didn't get the correct scope |
I never suggested you did. Was just wondering what did you mean by saying:
Specifically, what did you mean by "ready"? |
the custom directive is set up before ngController (the reasons why are silly, it's a combination of the priority and alphabetical order), so we set up a controller which uses properties set up in a controller which doesn't exist yet (and are thus undefined). The properties aren't ready yet, ergo, reference error |
I see! That makes perfect sense now! Thanks. |
duplicate of #1307 |
When I declare the controller at the same level of directive like this
http://plnkr.co/edit/ANkGH7r4GXyKLAFCTUWW?p=preview
I get a error while accessing the object passed to the directive in its controller.
TypeError: Cannot read property 'name' of undefined
at new controller (http://run.plnkr.co/2tcxCoWpBWVvSdXs/script.js:22:37)
at invoke (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:3979:17)
at Object.instantiate (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:3990:23)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:7281:28
at http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:6662:34
at forEach (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:327:20)
at nodeLinkFn (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:6649:11)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:6907:13
at http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:8021:11
at wrappedCallback (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.js:11410:81)
The text was updated successfully, but these errors were encountered: