Angular http post后刷新组件
我有一个模式来添加新项目(addProjectModal组件) 此组件用于我保存项目数据的projectComponent中Angular http post后刷新组件,angular,angular2-services,Angular,Angular2 Services,我有一个模式来添加新项目(addProjectModal组件) 此组件用于我保存项目数据的projectComponent中 ngOnInit() { this.collapsedItem = -1; this._projectService.getProjects(this.customerID) .subscribe(data => { this.projects = data }); } 您如何告诉父组件刷新(从数据库请求新数据)?我会说使用 @
ngOnInit() {
this.collapsedItem = -1;
this._projectService.getProjects(this.customerID)
.subscribe(data => {
this.projects = data
});
}
您如何告诉父组件刷新(从数据库请求新数据)?我会说使用
@输出()
为了这个
因此html代码如下所示:
<parentComponent>
<childComponent tellParent="parentFunction()"></childComponent>
</parentComponent>
谢谢!使用共享服务(单例)是否更好?在注入服务之前,是否可以在项目服务中填充共享项目数组(数据库的pout)?使用共享服务是个好主意,但如果您在子组件中没有任何用途,那么您希望在子组件和所有组件中添加服务引用,,但是,是的,可能是服务是另一种选择。我在两个组件中都使用该服务……但还不能作为singletongo和singletone
<parentComponent>
<childComponent tellParent="parentFunction()"></childComponent>
</parentComponent>