vib*_*97a 2 typescript angular
我是Angular的新手,这个问题可能听起来很愚蠢.请多多包涵.
我定义了我的ngOnInit
喜欢:
ngOnInit() {
this.rowData = this.studentService.getStudents();//Make http calls to populate data
}
Run Code Online (Sandbox Code Playgroud)
在一个事件中,我再次调用ngOnInit,因为我需要重新加载数据:
onSomeEvent(){
this.ngOnInit();
}
Run Code Online (Sandbox Code Playgroud)
这个可以吗?或者我应该写一行来再次调用http,如果这ngOnInit()
是一个昂贵的方法.
不,这不是一个好习惯.
更好的方法是从ngOnInit
需要时调用某些方法并重新调用相同的方法.像这样-
ngOnInit() {
this.onLoad();
}
onLoad() {
this.rowData = this.studentService.getStudents();//Make http calls to populate data
}
onSomeEvent(){
this.onLoad();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3454 次 |
最近记录: |