AngularJS - Can we remove/delete module? - javascript

I'm trying to clear memory of previous module of my app which Im not going to use after I've routed to a different location.
So for example my "WebApp" is my main angular module of my app which has dependency of "catalogApp", "PaymentApp", etc modules. I want to remove the previous module as and when I route from 1 module to another.
So, Can we remove/delete module?

I am not sure about deleting modules as such. But you can use ocLazyLoad to lazy load modules only when they are required.

Related

Is there a way to selectively use providers or services from one module into another instead of injecting whole module as dependency into another?

I have two angularjs modules. First module contains some services, components, styles, directive, providers and so on. Second module has its own services, components, directives and so.
I need only the styles, services and providers from module First in module Second. If i add First as a dependency in Second, whole module will load along with all components, which is not needed in Second.
So is there a way by which i can inject selectively i.e. services and providers from module First in Module Second without loading all unnecessary components and other code in angularjs 1.x ?

Angular Dynamically loaded module needs to use root injector service

I am loading module dynamically using system JS in Angular 6 and using angular-cli very similar to below link.
(Load new modules dynamically in run-time with Angular CLI & Angular 5)
Dynamically loaded module creates it's child injector and create new instance of services rather than using services from root injector.
As per Angular doc, lazy loaded module creates its own child injector and instances of service. In order to avoid that (for singleton), they suggest to create forRoot static method in lazy loaded module and import it in app module.
But in my case, as I am loading module at run time, I can't import LazyLoadedMOdule.forRoot() at bootstrap. I get to know which module is going to get loaded only at run time.
Can you please suggest to keep services singleton and use it in dynamically loaded module ?
For services that need to be singletons throughout the entire app, the recommended approach is to define those in a core module, which is then imported in the root module (AppModule).
You can refer to the Angular Style Guide for more detailed information.

Combining Angular (5.2) router with angular-ui-router (angular 1.3.19)

I'm building an app that should run inside of an AngularJS (1.3.19) module.
The motivation is to reuse AngularJS' already built services and controllers by the scope() and injector() functions.
I cannot use ng-upgrade because this will require refactoring a lot of our legacy code.
Is there a way I can combine two routers for two different AngularJS modules?
We use the angular-ui-router for our AngularJS app.
When I try to change a route on the Angular router, AngularJS' router removes the route and replaces it with an empty string (and runs the otherwise() function as configured).
Any ideas?
Thanks!
I got this.
Configure your paths on both ends. AngularJS' route should point at the html of your Angular app.
Also, I created a node script that imports Angular's routes and transforms them to be AngularJS' routes.
I did this with ts-node and webpack-shell-plugin.
Thanks.

how ngRoute works in background when include as dependency in angularjs?

When we write angular.module('app',['ngRoute']); what exactly dependencies here mean?
to be precise ngRoute is nothing but a simple angular module like
angular.module('ngRoute',['ng']) in which has $routeProvider
`angular.module('ngRoute',[]).provider('$roteProvider',[function(){}]).services('$route',function(){}).service('$routeParam',function(){})`
Its better to see the angular project in github https://github.com/angular/angular.js/blob/master/src/ngRoute/route.js
Dependencies means the list of modules that particular module in your case 'app' is dependent on , you when you state them as dependencies they get injected in the module at initialization and become available for usage

Disposing a RequireJS Required Class

Im using requireJS to dynamically load JS modules in my html5 single page web application. Im just wanting to know whether I should dispose of the requireJS loaded modules once i have finished with them (so the garbage collector can clean them up)? And if so than how do you dispose a required module from requireJS?
Thanks in advance
It is possible to undefine a module:
There is a global function, requirejs.undef(), that allows undefining
a module. It will reset the loader's internal state to forget about
the previous definition of the module. However, it will not remove the
module from other modules that are already defined and got a handle on
that module as a dependency when they executed. So it is really only
useful to use in error situations when no other modules have gotten a
handle on a module value, or as part of any future module loading that
may use that module. See the errback section for an example. If you
want to do more sophisticated dependency graph analysis for undefining
work, the semi-private onResourceLoad API may be helpful.
http://requirejs.org/docs/api.html#undef
I'm not too sure on the internals but in my usage of the lib I've not found it necessary to do any manual clean up of modules.

Categories

Resources