我試圖在我的面板上填入來自我的web api的資訊(已經作業了),但也要有通過我的面板向我的串列添加一個新點的選項。
我的復選框面板:
。< div class="generalCharacteristicsHover"(mouseleave)="hoveredPersonId = null">。
<h4> Allgemeine Merkmale </h4>
<div class="list-container"/span>>
<ng-container *ngFor="let char of allATypes"/span>>
<mat-checkbox name="aType.allgemeinesMerkmal.bezeichnung"
[checked]="checkAll(char. bezeichnung)" //getting default values form api
(change)="addToList($event)" //methodto add a new point
> {{char.bezeichnung}}。</mat-checkbox>{char.bezeichnung}}。
</ng-container>/span>
</div>/span>
</div>/span>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
我的名單:
< div id="GeneralCharacteristics">
<mat-label> Allgemeine Merkmale:</mat-label>
<ul>/span>
<li
*ngFor="let typB of aType">
{{typB.allogemeinesMerkmal.bezeichnung}} </li>
</ul>/span>
</div>/span>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
這里是我的方法,checkAll正在作業,addToList是我目前的問題。
。 checkAll(data: any){
for(let i = 0; i < this.aType.length; i ){
如果(this.aType[i].allgemeinesMerkmal.bezeichnung == data){
回傳true。
}
} 回傳 false。
}
addToList(event: any){
如果(event.target.checked){
this.aType.push(event.target.value)。
}
}
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
我不知道是否有必要,但這里也是我的訂閱:
//Allgemeine Merkmale
this.route.params.subscribe(params => {
const id = params['id'];
this.amService
.getTypeId(id)
.subscribe(data => { this.aType = data; console.log(this.aType);
this.amService.getTypeId(id).toPromise().then(result =>{
this.checkboxesLoaded = true;
})})
<iframe name="sif4" sandbox="allow-form allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
。
core.js:6479 ERROR TypeError: 無法讀取未定義的屬性(讀取'checked')。
at ProfilansichtComponent.addToList ( profilansicht.component.ts:143)
<iframe name="sif5" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
我自己用
解決了這個問題。 。console.log("pushed " data "to List")。
console.log(this.aType)。
this.aType.push(data);
<iframe name="sif6" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
想的太復雜了
uj5u.com熱心網友回復:你使用Angular Material checkbox API,更確切地說,是change事件。
它輸出一個型別為MatCheckboxChange的物件,該物件有一個你想要的checked屬性。
你的錯誤在這里:
addToList(event: any){
if(event.target.checked){ // <---
this.aType.push(event.target.value)。
}
它應該是
addToList(event: any){
如果(event.checked){
this.aType.push(event.checked)。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/323554.html
標籤:
