解決angular11打包報錯Type 'Event' is missing the following properties from type 'any[]': ...Type 'Event' is not assignable to type 'string'


出現這種情況,需要檢查一下以下事項

1.ts類型聲明和html里寫的是否一致

1.1舉例如下,子組件代碼需要注意事項,子組件調用父組件方法,點擊傳參給父組件,在父組件觸發一些時間,當前this指向是父組件的this

<button  (click)="sentToParent(data)">點擊傳參給父組件,在父組件觸發一些時間,當前this指向是父組件的this</button>

 @Input()
  public childObjData = {  
    a: '',
    b: '',
    c: [],
    d: [],
    e: []
  }
  @Output()
  private outer : EventEmitter<any> = new EventEmitter(); // 注意此處的類型聲明格式

  sentToParent(e) {
    // this.bottomTable.pageNo = e
    this.outer.emit(e)
  }

1.2父組件傳參給子組件

<child-component class="my-child-component" [childObjData]="sendToChildObjData"  (outer)="fromChildEvent($event)"></child-component>
  
  
  sendToChildObjData = { 
    a: '',
    b: '',
    c: [],
    d: [],
    e: []
  }
  
  
  fromChildEvent(e) {
    //  console.log(e)
    //  此處的this是父組件的this
    this.XXXX()
  }

2.父子組件傳參,注意格式

下面是父組件的,注意一下傳參的() 和 [],不要寫錯了

 <child-component class="my-child-component" [childObjData]="childObjData"  (outer)="childEent($event)"></child-component>

3.檢查一下VScode控制台里PROBLEMS里有沒有一些問題沒有處理的~~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM