store.js
import {Injectable, Input} from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class Store {
// 游戏大种类id
public game_type: BehaviorSubject<any[]> = new BehaviorSubject([]);
constructor(
) {
}
}
别的文件,修改变量的地方 this.store.game_type.next(data['game_type']);
监听变量更改的地方
public sub_game_type:Subscription;
this.sub_game_type = this.store.game_type.subscribe(data => {
if(data) {
}
})
取消监听 ngOnDestroy() { this.sub_game_type.unsubscribe(); }