angular.js/src
Vojta Jina 742271ffa3 fix($compile): link parents before traversing
How did compiling a templateUrl (async) directive with `replace:true` work before this commit?
1/ apply all directives with higher priority than the templateUrl directive
2/ partially apply the templateUrl directive (create `beforeTemplateNodeLinkFn`)
3/ fetch the template
4/ apply second part of the templateUrl directive on the fetched template
(`afterTemplateNodeLinkFn`)

That is, the templateUrl directive is basically split into two parts (two `nodeLinkFn` functions),
which has to be both applied.

Normally we compose linking functions (`nodeLinkFn`) using continuation - calling the linking
function of a parent element, passing the linking function of the child elements as an argument. The
parent linking function then does:
1/ execute its pre-link functions
2/ call the child elements linking function (traverse)
3/ execute its post-link functions

Now, we have two linking functions for the same DOM element level (because the templateUrl directive
has been split).

There has been multiple issues because of the order of these two linking functions (creating
controller before setting up scope locals, running linking functions before instantiating
controller, etc.). It is easy to fix one use case, but it breaks some other use case. It is hard to
decide what is the "correct" order of these two linking functions as they are essentially on the
same level.

Running them side-by-side screws up pre/post linking functions for the high priority directives
(those executed before the templateUrl directive). It runs post-linking functions before traversing:
```js
beforeTemplateNodeLinkFn(null); // do not travers
afterTemplateNodeLinkFn(afterTemplateChildLinkFn);
```

Composing them (in any order) screws up the order of post-linking functions. We could fix this by
having post-linking functions to execute in reverse order (from the lowest priority to the highest)
which might actually make a sense.

**My solution is to remove this splitting.** This commit removes the `beforeTemplateNodeLinkFn`. The
first run (before we have the template) only schedules fetching the template. The rest (creating
scope locals, instantiating a controller, linking functions, etc) is done when processing the
directive again (in the context of the already fetched template; this is the cloned
`derivedSyncDirective`).

We still need to pass-through the linking functions of the higher priority directives (those
executed before the templateUrl directive), that's why I added `preLinkFns` and `postLinkFns`
arguments to `applyDirectivesToNode`.

This also changes the "$compile transclude should make the result of a transclusion available to the
parent directive in post- linking phase (templateUrl)" unit test. It was testing that a parent
directive can see the content of transclusion in its pre-link function. That is IMHO wrong (as the
`ngTransclude` directive inserts the translusion in its linking function). This test was only passing because of
c173ca4128, which changed the behavior of the compiler to traverse
before executing the parent linking function. That was wrong and also caused the #3792 issue, which
this change fixes.

Closes #3792
Closes #3923
Closes #3935
Closes #3927
2013-09-30 15:30:29 -07:00
..
auto fix($injector): don't parse fns with no args 2013-08-16 11:01:51 -07:00
ng fix($compile): link parents before traversing 2013-09-30 15:30:29 -07:00
ngAnimate fix($animate): ensure transition-property is not changed when only keyframe animations are in use 2013-09-30 10:59:28 -07:00
ngCookies docs(module): improve the installation instructions for optional modules 2013-08-22 16:55:54 -07:00
ngLocale fix(i18n): remove obsolete locale files 2013-08-27 15:55:37 -07:00
ngMock docs(mocks): fix syntax error in example 2013-09-28 20:23:18 +01:00
ngResource docs(ngResource): fix typo 2013-09-18 14:40:22 +01:00
ngRoute docs($route): reloadOnSearch affects hash fragment changes 2013-09-30 14:04:59 -07:00
ngSanitize fix(ngSanitize): sanitizer should not accept <!--> as a valid comment 2013-09-11 22:40:09 +02:00
ngScenario feat(browserTrigger): allow support for custom timeStamps in events 2013-09-26 11:19:43 -07:00
ngTouch docs(module): improve the installation instructions for optional modules 2013-08-22 16:55:54 -07:00
Angular.js docs(angular.copy): add an example with the two possible arguments 2013-09-30 22:15:57 +01:00
angular.prefix chore(license): update to google 2012-04-20 11:29:34 -07:00
angular.suffix fix(init): use jQuery#ready for init if available 2012-03-23 15:41:37 -07:00
AngularPublic.js feat(ngAnimate): complete rewrite of animations 2013-07-26 23:49:54 -07:00
apis.js feat(ngRepeat): add support for custom tracking of items 2013-03-29 23:01:52 -07:00
jqLite.js fix(jqLite): use get/setAttribute so that jqLite works on SVG nodes 2013-09-27 12:38:27 -07:00
loader.js docs(angular.Module): fix controller and directive method parameters 2013-09-27 16:10:43 -07:00
loader.prefix chore(license): update to google 2012-04-20 11:29:34 -07:00
loader.suffix feat(module): new module loader 2012-01-10 22:27:00 -08:00
minErr.js feat(minerr): log minerr doc url in development 2013-08-15 13:23:18 -07:00
module.prefix chore(module): improved module prefix/suffix code 2012-05-04 15:50:37 -07:00
module.suffix chore(module): improved module prefix/suffix code 2012-05-04 15:50:37 -07:00
publishExternalApis.js chore(Rakefile): get ready for modules 2012-03-28 11:16:36 -07:00