angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.8k stars 27.49k forks source link

Feat: provider/decorator/controller/directive/filter unregistration #13170

Closed amitport closed 7 years ago

amitport commented 9 years ago

use case: I have many routes in a single page app, in some routes I want to define controllers and directive (and possibly other injectables) that should only be available in those routes.

In order to avoid memory bloating and name collision (for directive/controller names etc.), I want to unregister such injected objects when leaving each route.

If I understand correctly, this is possible using something like:

var noopDirective = function() { return function () {}; };
$compileProvider.directive('directiveToUnregister', noopDirective)

but this is very ugly and it would be nice if the following would be supported:

$injector.unregister('injectableToUnregister')
Narretz commented 9 years ago

If I'm not mistaken, unregistering the directive in your example isn't going to work, as you are simply registering another directive with the same name that does nothing.

As for unregistering, I'm not sure if it is a common feature, but it would probably work reasonably easy for services etc. but directives might be more difficult because you can register the same name multiple times.

Narretz commented 7 years ago

This is out of scope for AngularJS