【发布时间】:2018-08-30 05:20:50
【问题描述】:
我是 Angular 6 的新手。我有 header component 和 dashboard component。
在我的header comp 中,我弹出通知列表,其中包含带有接受和删除选项的通知列表。
在我的dashboard component 中,我有已接受通知的列表。
如果我接受来自标题的新通知,则应在仪表板中更新列表。
在我的标题组件中,我包含了 flowwing
import { DashboardComponent } from '../../pages/dashboard/dashboard.component';
// 包含仪表板组件作为提供者
@Component({
selector: 'app-siteheader',
providers:[DashboardComponent ],
templateUrl: './siteheader.component.html',
styleUrls: ['./siteheader.component.css']
})
// 在名为dashcomp的构造函数中
constructor( private dashcomp: DashboardComponent, private dashboardservice: DashboardService, private authenticationService: AuthenticationService) { }
// 通知接受动作
actionaccept(id){
this.authenticationService.acceptaction(id)
.subscribe(
data => {
// caled the dashboard function
this.loaddashboard();
}
);
}
//通过使用这个函数调用仪表板组件的函数。
public loaddashboard() {
console.log('called');
this.dashcomp.dolist('future');
}
在仪表板组件中:
dolist(type) {
console.log('dasss');
this.dashservice.listengagement(type,this.page,this.limit)
.subscribe(
data => {
console.log(data);
this.futureloader = false;
this.futurelist = data['result'];
this.futuretotal = data['count'];
}
);
}
在仪表板 html 中使用 ngfor 显示的结果
我的问题是::从标题中触发了仪表板功能。它显示控制台。但是仪表板中的输出没有改变。我有什么遗漏吗??
【问题讨论】:
-
将 BehaviorSubject 与 Observable 一起使用
-
您可以在服务中使用单例行为主体。在需要一致数据的任何地方更新并订阅它。 blog.angular-university.io/…
标签: angular typescript npm angular6