从另一个角度4获取值
发布时间:2020-12-17 09:03:31 所属栏目:安全 来源:网络整理
导读:我有两个独立的组件;一个包含选择搜索框的标题组件,stats组件根据选择框的值显示结果,我想知道一旦选择框改变是否可以刷新结果,我想到使用LocalStorage但它看起来像一个懒惰的解决方案. 使用共享服务: 服务: @Injectable()export class MyService { myMeth
我有两个独立的组件;一个包含选择搜索框的标题组件,stats组件根据选择框的值显示结果,我想知道一旦选择框改变是否可以刷新结果,我想到使用LocalStorage但它看起来像一个懒惰的解决方案.
使用共享服务:
服务: @Injectable() export class MyService { myMethod$: Observable<any>; private myMethodSubject = new Subject<any>(); constructor() { this.myMethod$= this.myMethodSubject.asObservable(); } myMethod(data) { console.log(data); // I have data! Let's return it so subscribers can use it! // we can do stuff with data if we want this.myMethodSubject.next(data); } } Component1(发件人): export class SomeComponent { public data: Array<any> = MyData; public constructor(private myService: MyService) { this.myService.myMethod(this.data); } } Component2(接收器): export class SomeComponent2 { public data = {}; public constructor(private myService: MyService) { this.myService.myMethod$.subscribe((data) => { this.data = data; // And he have data here too! } ); } } Check documentation! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- angularjs – ng -inc with $state.go()来自ui-router无法正
- Angular4-在线竞拍应用-路由
- 一条语句查看web日志排名前十的IP/URL页面及总数
- 玩转Bootstrap(基础) -- (5.下拉菜单)
- *.ascx *.asax *.aspx.resx *.asax.resx是什么文件
- 开放《数据结构》专栏的代码
- scala – 如何将Akka Streams Merge的输出传输到另一个流?
- scala – 在Apache Flink上的zipWithIndex
- PowerShell分割按行数分割文本文件
- webservice 出现No service was found