首页 > 解决方案 > 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>

标签: javascriptangulartypescriptionic-framework

解决方案


推荐阅读