{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular.js/issues/8877","labels_url":"https://api.github.com/repos/angular/angular.js/issues/8877/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular.js/issues/8877/comments","events_url":"https://api.github.com/repos/angular/angular.js/issues/8877/events","html_url":"https://github.com/angular/angular.js/issues/8877","id":41649829,"number":8877,"title":"Parent directive goes through compile, pre, and post before child directive with templateUrl","user":{"login":"ryanzec","id":444206,"avatar_url":"https://avatars.githubusercontent.com/u/444206?v=3","gravatar_id":"","url":"https://api.github.com/users/ryanzec","html_url":"https://github.com/ryanzec","followers_url":"https://api.github.com/users/ryanzec/followers","following_url":"https://api.github.com/users/ryanzec/following{/other_user}","gists_url":"https://api.github.com/users/ryanzec/gists{/gist_id}","starred_url":"https://api.github.com/users/ryanzec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryanzec/subscriptions","organizations_url":"https://api.github.com/users/ryanzec/orgs","repos_url":"https://api.github.com/users/ryanzec/repos","events_url":"https://api.github.com/users/ryanzec/events{/privacy}","received_events_url":"https://api.github.com/users/ryanzec/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular/angular.js/labels/resolution:%20works%20as%20expected","name":"resolution: works as expected","color":"207de5"}],"state":"closed","locked":false,"assignee":{"login":"petebacondarwin","id":15655,"avatar_url":"https://avatars.githubusercontent.com/u/15655?v=3","gravatar_id":"","url":"https://api.github.com/users/petebacondarwin","html_url":"https://github.com/petebacondarwin","followers_url":"https://api.github.com/users/petebacondarwin/followers","following_url":"https://api.github.com/users/petebacondarwin/following{/other_user}","gists_url":"https://api.github.com/users/petebacondarwin/gists{/gist_id}","starred_url":"https://api.github.com/users/petebacondarwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petebacondarwin/subscriptions","organizations_url":"https://api.github.com/users/petebacondarwin/orgs","repos_url":"https://api.github.com/users/petebacondarwin/repos","events_url":"https://api.github.com/users/petebacondarwin/events{/privacy}","received_events_url":"https://api.github.com/users/petebacondarwin/received_events","type":"User","site_admin":false},"milestone":null,"comments":18,"created_at":"2014-09-01T16:09:16Z","updated_at":"2015-05-20T14:05:12Z","closed_at":"2014-09-02T14:38:22Z","body":"I think there is a bug with the ordering of compile, pre, and post linking functions in parent directives when a child directive uses templateUrl to get the template.\r\n\r\nHere are some simple directived, not using the `template` or `templateUrl` properties:\r\n\r\nhttp://plnkr.co/edit/gEk3GjuASxrV1L6Kp6Dq?p=preview\r\n\r\nEverything happens in the order I expect.\r\n\r\nNext we use the `template` property for the `logCompile2` directive:\r\n\r\nhttp://plnkr.co/edit/EOYgf5z82mesixcb1LXU?p=preview\r\n\r\nAgain everything works as expected.\r\n\r\nFinally we use the `templateUrl` property for the `logCompile2` directive:\r\n\r\nhttp://plnkr.co/edit/A55sw6YRCuhvWUi6zQ4Q?p=preview\r\n\r\nThis is where things go wrong as the parent directive is running through all the steps before any of the steps of the child directives are linked.\r\n\r\nSome else played with this that last plunker and added transclusion with weird results too:\r\n\r\nhttp://plnkr.co/edit/0jjwTk8VGoqjSF9se1KZ?p=preview\r\n\r\nThe documentation states:\r\n\r\n```\r\nPost-linking function\r\n\r\nExecuted after the child elements are linked. It is safe to do DOM transformation in the\r\npost-linking function.\r\n```\r\n\r\nEither I am miss understanding the documentation or this is a bug as I would except the child directive to compile and run pre/post linking before the parent's post linking would run (as the non-templateUrl example do).\r\n\r\nIs this a bug or am I miss understanding something?\r\n\r\nI should mention this is an issue with 1.2.23 and 1.3.0-rc.0"},"comment":{"url":"https://api.github.com/repos/angular/angular.js/issues/comments/103898850","html_url":"https://github.com/angular/angular.js/issues/8877#issuecomment-103898850","issue_url":"https://api.github.com/repos/angular/angular.js/issues/8877","id":103898850,"user":{"login":"raphaelduartepinheiro","id":901936,"avatar_url":"https://avatars.githubusercontent.com/u/901936?v=3","gravatar_id":"","url":"https://api.github.com/users/raphaelduartepinheiro","html_url":"https://github.com/raphaelduartepinheiro","followers_url":"https://api.github.com/users/raphaelduartepinheiro/followers","following_url":"https://api.github.com/users/raphaelduartepinheiro/following{/other_user}","gists_url":"https://api.github.com/users/raphaelduartepinheiro/gists{/gist_id}","starred_url":"https://api.github.com/users/raphaelduartepinheiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raphaelduartepinheiro/subscriptions","organizations_url":"https://api.github.com/users/raphaelduartepinheiro/orgs","repos_url":"https://api.github.com/users/raphaelduartepinheiro/repos","events_url":"https://api.github.com/users/raphaelduartepinheiro/events{/privacy}","received_events_url":"https://api.github.com/users/raphaelduartepinheiro/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T14:05:12Z","updated_at":"2015-05-20T14:05:12Z","body":"A way to overcome this problem is use $watch to check if the element inside the child directive is not undefined.\r\n\r\nExample:\r\n\r\n   scope.$watch(function() {\r\n                  var input = formGroup.querySelectorAll('input')\r\n                  if (!input) return // check if its undefined\r\n\r\n                  // continue to manipulate children elements...\r\n   }\r\n"}}