javascript - NgOnInit - IonWillEnter 错误:未捕获(承诺中):TypeError:无法读取 null 的属性“出口”
问题描述
在 ionic5/angular 应用程序中加载组件时遇到问题。我收到以下错误:
“错误:未捕获(承诺中):TypeError:无法读取 null 的属性 'outlets'”
当初始化代码在 IonViewWillEnter 方法中时。
ionViewWillEnter(){
this.appDataService.changePageName('Visita.Detalle.title');
this.controles = this.route.snapshot.data['controles'];
this.visita = this.route.snapshot.data['visita'];
this.idVisita = +this.route.snapshot.paramMap.get('id');
this.authService.getUserSubject().subscribe(
data => this.currentUser = data,
error => console.log(error)
);
console.log(this.controles)
for(let control of this.controles){
//Convierto tipo de datos firestore en date
if(control.fecha.seconds) control.fecha = new Date(control.fecha.seconds * 1000)
this.ubicacionService.obtenerUbicacion(control.ubicacionId).subscribe(
data => {
control.ubicacion = data.nombre
console.log(control)
},
(error) => console.log(error)
)
}
console.log(this.controles)
console.log(this.visita)
}
在 ngOnInit 中使用相同代码时,问题消失。但是 NgOnIt 在返回页面时不会触发,这是一种期望的行为。
我认为问题与模板的这一部分有关:
<ion-fab-button color="warning" [routerLink]="['/irregularidad','establecimiento', visita?.establecimientoId ,'alta']">
<ion-icon name="alert-circle-outline"></ion-icon>
</ion-fab-button>
解决方案
推荐阅读
- c - 为什么我的浮点变量不能存储小数点后的数字?
- r - 错误:创建 data.frame 时使用旧格式损坏 grouped_df 数据?
- ruby-on-rails - 如何在 Ruby on Rails Active Storage 上为 S3 设置传输加速
- visual-studio - 在 Visual Studio for Mac 中打开文件后出错
- python - Python - 如何将带有“+”号的字符串转换为日期时间?
- cookies - HTTP API Gateway JWT Authorizer 从 cookie 获取身份源
- sql - A 和 B 均发生的案例,两次列出该案例
- python - 两个运行脚本之间的通信
- google-sheets - 如何使importxml只给出一定的数据
- c# - 如何根据复选框列表选择值在c#中随机调用函数?