Emit and broadcast events throughout application in Angular

我的梦境 提交于 2019-12-06 13:20:55
Günter Zöchbauer

In Angular2 there is no global scope. There are only components and services.

With services you can define their scope by the place you provide them. If you provide one in @NgModule({providers: ...}) (or in an imported module) it becomes globally avialable. If you provide it at a component, it is only available to this component and its children.

For examples how to use shared services see https://github.com/dart-lang/sdk/issues/27637

You can also dispatch a bubbling DOM event like shown in in Angular2 how to know when ANY form input field lost focus

Events emitted with @Output() someOutput:EventEmitter = new EventEmitter(); don't bubble.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!