You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my @NgModule > providers, I add a service named "myService", beacause I want a unique instance of my service in the whole App. In my components I can inject my services which share the same instance of the service.
So now, in my State declaration, I add a resolvable :
{
name: 'myState',
url: '/user/:userId',
component: ViewUserComponent,
resolve: [
new Resolvable('user', (http, trans, uService) => {
return new Promise((resolve, reject) => {
let id = trans.params().userId;
http
.get('myUrl ' + id)
.subscribe((res: Response) => {
let u = new User(res.json());
new uService.add(u);
resolve(u);
}, reject);
});
}, [Http, Transition, userService])
]
}
In my userService constructor I put a console.log, and I can see multiple "construct UserService". Xhy UIRouter don't take the app instance of the service? How can I force him to use this one ?
The text was updated successfully, but these errors were encountered:
The new uService.add(u); line looks suspicious. UI-Router will not itself create new instances of global services for injection. It either fetches an object from the resolve system or from Angular's DI system. Here's a stackblitz showing how it should work: https://stackblitz.com/edit/ui-router-angular-wgqmfj?file=app%2Fapp.module.ts
Hi ! some problems with my States.
In my @NgModule > providers, I add a service named "myService", beacause I want a unique instance of my service in the whole App. In my components I can inject my services which share the same instance of the service.
So now, in my State declaration, I add a resolvable :
In my userService constructor I put a console.log, and I can see multiple "construct UserService". Xhy UIRouter don't take the app instance of the service? How can I force him to use this one ?
The text was updated successfully, but these errors were encountered: