typescript 类型“string”不能赋给类型“null”,更新离子后出现ts(2322)错误

mbzjlibv  于 2023-03-13  发布在  TypeScript
关注(0)|答案(1)|浏览(280)

我使用下面的代码为侧边菜单超过两年,直到离子版本5现在更新离子到6.20.6和Angular 15^我得到下面的错误在
否则{此显示级别1 = idx;*
类型“string”不能赋给类型“null”。ts(2322)

export class AppComponent {
  public appPages: any;
  showLevel1 = null;
  showLevel2 = null;
   @ViewChildren(IonRouterOutlet) routerOutlets: QueryList<IonRouterOutlet>;

  
 
  clearLevel() {
    this.showLevel1 = null;
    this.showLevel2 = null;
  //  this.showLevel3 = null;
  }
  toggleLevel1(idx: string) {
    if (this.isLevel1Shown(idx)) {
      this.showLevel1 = null;
    } else {
      this.showLevel1 = idx;
    }
    
  }
  isLevel1Shown(idx: string) {
    
    return this.showLevel1 === idx;
  }
jpfvwuh4

jpfvwuh41#

最新的ionic嵌入了字符串类型。如果要将变量/成员变量用作字符串,请分配空字符串。例如,

showLevel1:string="";

相关问题