angular 组件通信的几种实现方式(3)

@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app'; message: string; constructor(private alertService: AlertService) { //订阅alertServcie的message服务 this.alertService.messageObserve.subscribe((res: any) => { this.message = res; }); } }

这样订阅者就能动态的跟着发布源变化

总结: 以上就是常用的的通信方式,各种场景可以采取不同的方法。希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b81e31ad97bccbb2ccf6840715306303.html