问题
I am working on Angular6 todo list task app. I have tasks categories when click on category I get this category's tasks it working with me well but I need to set categories in nav-component like image below. so I need store selected category id in value to use it in todo-component any help ..?
回答1:
I found a way to make a shareable Object :
create new service called GlobaleVariable.ts and write this on it :
@Injectable()
export class GlobalVariblesClass {
sharedCategory$ = new ReplaySubject<Groups>(1);
updateCategoryValue(g: Groups) {
return this.sharedCategory$.next(g);
}
}
then you can inject this class in any Component Constructor to use it :)
来源:https://stackoverflow.com/questions/53457721/shared-variable-used-globally-in-angular-6-components