Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Isolated scope properties are not available in 'pre' link function when using 'templateUrl' #2064

Closed
dana-shalev opened this issue Feb 25, 2013 · 7 comments

Comments

@dana-shalev
Copy link

I have an isolated directive which initializes its scope properties in the directive.scope attribute. In the pre link function I'm using those scope attributes.
However, I discovered that if i used 'templateUrl' instead of 'template' in my directive suddenly things stop working.

Apparently when I switched to use 'templateUrl' suddenly the 'pre' link function was called before the scope was initialized with the properties I defined in the directive.scope property.

Take a look at this plunker for an example:

  • The message directive defines an isolated scope which has a message property taken from the attribute.
  • When I print to the console the value of message from the pre function I get undefined (while in the post function I get the actual value).
  • If I comment the templateUrl property and use template instead the pre function will also print the actual value.
@petebacondarwin
Copy link
Contributor

I think you are right that this is a bug. Although template loading is asynchronous, it seems that the template has been loaded by the time the pre-link is called and but the set-up of the isolated scope has not occurred.
See this fiddle (http://plnkr.co/edit/n9EEOS1jm7aXIH37XfiF?p=preview) and put break points on the pre and post link functions as well as line 4265 of angular.js

@billstar
Copy link

I'm seeing a different, but related bug where scope vars prefixed with @ that are referenced in the link function, when $observed or not, are also undefined, only when using the templateUrl attribute.

@ryanzec
Copy link

ryanzec commented Jun 20, 2013

Any update on this?

I mean I can use the template property but it would be a lot cleaner to be able to use a separate file and use the templateUrl.

@ivarni
Copy link

ivarni commented Aug 9, 2013

Having the same issue in 1.0.5 and 1.0.7

@derekrprice
Copy link

Experiencing this issue in 1.2.0rc1.

@trask
Copy link

trask commented Sep 30, 2013

This is fixed by #3927

@Narretz
Copy link
Contributor

Narretz commented Dec 19, 2013

@petebacondarwin then it can be closed!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants