Title: SCOPE DESTRUCTION: Directive scope is never destroyed if immediately switched out and it has templateUrl. · Issue #9197 · angular/angular.js · GitHub
Open Graph Title: SCOPE DESTRUCTION: Directive scope is never destroyed if immediately switched out and it has templateUrl. · Issue #9197 · angular/angular.js
X Title: SCOPE DESTRUCTION: Directive scope is never destroyed if immediately switched out and it has templateUrl. · Issue #9197 · angular/angular.js
Description: AngularJS - HTML enhanced for web apps! Contribute to angular/angular.js development by creating an account on GitHub.
Open Graph Description: AngularJS - HTML enhanced for web apps! Contribute to angular/angular.js development by creating an account on GitHub.
X Description: AngularJS - HTML enhanced for web apps! Contribute to angular/angular.js development by creating an account on GitHub.
Opengraph URL: https://github.com/angular/angular.js
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SCOPE DESTRUCTION: Directive scope is never destroyed if immediately switched out and it has templateUrl.","articleBody":"We have a directive which uses `templateUrl` that is rendered within a `ngSwitch`. There is a scenario where on page load the directive is rendered, but then immediately some conditions change causing `ngSwitch` to remove the directive from page. I found that in that case the directive's scope never gets destroyed.\n\nA Plunker demo is available here - http://plnkr.co/edit/QYnUKQrHA4uivJifsYne?p=preview\n\nIn the demo open browser's JS console. Notice that you will only see '>>>Created' message, but no '>>>Destroyed'. This bug happens only when the directive uses `templateUrl`. If you change the above demo code to use `template` instead then notice the bug is gone.\n\nThe html snippet is:-\n\n```\n\u003cbody ng-controller=\"Main\">\n\u003cdiv>\n \u003cdiv ng-switch=\"code\">\n \u003cdiv ng-switch-when=\"red\">\n \u003cred>\u003c/red>\n \u003c/div>\n \u003c/div>\n\u003c/div>\n\u003c/body>\n```\n\nThe controller code is:-\n\n```\ncontroller('Main', function ($scope, $timeout) {\n $scope.code = 'red';\n $timeout(function () {\n $scope.code = 'blue';\n })\n})\n```\n\nSo as soon as the controller loads, `$scope.code` is set to 'blue' in next digest cycle, causing the directive `red` to appear momentarily.\n\nThe directive code is:-\n\n```\ndirective('red', function () {\n return {\n restrict: 'E',\n replace: true,\n templateUrl: 'red.html',\n scope: {},\n link: function (scope) {\n console.log('>>>Created');\n scope.$on('$destroy', function (event) {\n console.log('>>>Destroyed');\n })\n }\n };\n})\n```\n\nIf I use `template` instead of `templateUrl`, then `$destroy` is called. The `replace: true` or isolated scope are not necessary to replicate this bug.\n","author":{"url":"https://github.com/applegrew","@type":"Person","name":"applegrew"},"datePublished":"2014-09-21T04:39:10Z","url":"https://github.com/angular/angular.js/issues/9197"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:716430db-5d80-957d-2762-4d21a86be221 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E46A:3713AD:34E85:49C54:6AFDFA36 |
| html-safe-nonce | 1a26c24907969c01553b7991406a75e552859edd12b72a9e3725d9c485d70134 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDZBOjM3MTNBRDozNEU4NTo0OUM1NDo2QUZERkEzNiIsInZpc2l0b3JfaWQiOiI3NDE0OTc0MDgyOTg0MDQ5MjA2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bdd46122e17cda9b617a747624f35f82320903aa6125ec4c5b06a203b6e653f2 |
| hovercard-subject-tag | repository:460078 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angular.js/issues/9197 |
| twitter:image | https://opengraph.githubassets.com/1fb96cabe75dcd53decb642c7e3404dd30d5589daaa5c359b9e911fc4688e2cd/angular/angular.js |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1fb96cabe75dcd53decb642c7e3404dd30d5589daaa5c359b9e911fc4688e2cd/angular/angular.js |
| og:image:alt | AngularJS - HTML enhanced for web apps! Contribute to angular/angular.js development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ee3343385a977757dd145b28fabf4a119780f2615a5a36c5a89f66c9b3b5616d |
| turbo-cache-control | no-cache |
| go-import | github.com/angular/angular.js git https://github.com/angular/angular.js.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 460078 |
| octolytics-dimension-repository_nwo | angular/angular.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 460078 |
| octolytics-dimension-repository_network_root_nwo | angular/angular.js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 43ae91995f6e2d5ff7a491f3de438f1f723adeaa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width