There are different way:
-
global service
-
service shared by parent and injected to the child
- similar to global service but listed in
providers
orviewProviders
in the parent instead ofboostrap(...)
and only available to children of parent.
- similar to global service but listed in
-
parent injected to the child and accessed directly by the child
- disadvantage: tight coupling
export class Profile implements OnInit {
constructor(@Host() parent: App) {
parent.userStatus ...
}
- data-binding
export class Profile implements OnInit {
@Input() userStatus:UserStatus;
...
}
<profile [userStatus]="userStatus">