从编辑页 edit.ts 获取成功后,我正在导航到查看页面(view.ts)。导航到查看页面时,我将布尔isShowDialog = true
作为输入传递给 view.ts ,但该值未在视图页面中接收。
edit.ts
@Output() isShowDialog1 = new EventEmitter<boolean>();
editBusinessData(data) {
let isShowDialog = true;
** some code missing **
this.isShowDialog1.emit(isShowDialog);
this.router.navigate(['/cloud/configuration/roomtypes/view']);
}
view.ts
@Input() isShowDialog;
ngOnInit() {
console.log('view 41', this.isShowDialog); //output view41 undefined
}
答案 0 :(得分:0)
您必须传递路线中的数据,然后在目的地中,您可以从路线中读取相同的数据。另请参阅Route parameters in the ActivatedRoute service。
<强> edit.ts 强>
editBusinessData(data) {
let isShowDialog = true;
this.router.navigate(['/cloud/configuration/roomtypes/view', {isShowDialog: isShowDialog}]);
}
<强> view.ts 强>
import { Params, ActivatedRoute } from '@angular/router';
export class ViewComponent implements OnInit {
isShowDialog: boolean;
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.params.subscribe(params => {
this.isShowDialog = params.get('isShowDialog').toLower() === 'true';
});
}
}