路由守卫:
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):DiseaseBaseInfo | Observable<DiseaseBaseInfo> | Promise<DiseaseBaseInfo> {
const diseaseid=route.queryParams['id'];
// const diseaseid = route.params['id'];
const geturl = this.diseasewebapiroot + '/GetDiseaseBaseInfoById?diseaseid='+diseaseid;
this.disease = this.http.get(geturl).map(response => response.json());
let diseasebaseinfo=new DiseaseBaseInfo();
this.disease.subscribe(data => {
diseasebaseinfo.Id=data.Data['Id'];
diseasebaseinfo.StandardName=data.Data['StandardName'];
diseasebaseinfo.Name=data.Data['Name'];
diseasebaseinfo.Sex=data.Data['Sex'];
});
return diseasebaseinfo;
}
组件:
ngOnInit() {
// 从路由守卫Resolve返回的数据中才初始化
this.routedatainfo.data.subscribe((data: { diseaseeditinfo: DiseaseBaseInfo }) => {
this.diseasedata = data.diseaseeditinfo;
});
}
组件页面:
<input id="standardname" type="text" class="form-control" [formControl]="myevent" [(ngModel)]="diseasestandardname" value="{{diseasedata.StandardName}}">
可以正常绑定对象的属性值,但在组件的方法 初始方法中要获取到:this.diseasedata.StandardName确报
undefined错误,请问这是怎么回事?
全网首个介绍官方 Material 组件库用法与 Redux 在 Angular 中的应用
了解课程