-2

我正在为我的项目使用https://github.com/mgechev/angular-seedheader单击addtocart我的组件时,我需要通过组件更新购物车中的值item。请帮我。我是 Angular 2 的新手。我使用了与https://github.com/mgechev/angular-seed中相同的代码结构。

4

2 回答 2

0

您可以使用角度服务在组件、指令和服务之间进行通信。您还可以使用@Input 和@Output 在父子组件之间进行通信。还有其他方法,具体取决于您的需要...检查角度页面:

https://angular.io/docs/ts/latest/cookbook/component-communication.html

于 2016-12-25T11:56:11.760 回答
-1

使用主题类型(可观察)定义服务中的属性并在子组件中调用或使用该属性,使用下一个函数并在下一个函数中传递数据。在父组件中只需订阅这个 observable。以下https://github.com/aryanisml/Angular-Services-Observables 将为您提供帮助。

于 2017-12-28T06:57:14.650 回答