第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

獲取 *ngFor 中的文本長度

獲取 *ngFor 中的文本長度

Qyouu 2021-11-04 17:41:41
我對 Angular (8) 還很陌生,我嘗試獲取輸入值的長度,我以*ngFor如下方式創(chuàng)建了它:<div *ngFor="let panel of panels; index as i" class="panel" [id]="'panel-' + panel.id">    <div>{{ panel.title }}</div>    <input matInput placeholder="Bezeichnung" [(ngModel)]="panel.title" /></div>我將如何訪問panel.title班級中的長度?這是我的接口/類export interface ProgressbarStepData {    // Each progressbar step is represented by an instance of this data type.    id: number; // Unique ID    title: string; // The label that is displayed as the step title.    color: string; // Hex code of the colored markings associated with this step. Only visible in Builder, not Viewer.    order: number; // Denotes which step this is (from step 1 to <number of steps>)}export class ProgressbarEditorComponent implements OnInit {    public panels: Array<ProgressbarStepData> = []; // One panel for each existing progressbar step   ...我需要什么才能獲得當前輸入的輸入長度?編輯澄清我想要實現(xiàn)的目標:我想計算在 CURRENT 輸入中鍵入的字符數并觸發(fā)來自類的警報(而不是來自模板本身)
查看完整描述

3 回答

?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

.html

<input type="text" (input)="inputMthd($event)"  (keyup)="methodCalled($event)">

.ts

inputMthd(e){

console.log(e);

event.target.value.length;

}

methodCalled(e){

console.log(e);

e.target.value.length;

}


查看完整回答
反對 回復 2021-11-04
?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

您ngModel需要綁定到panels不panel中ngFor。您可以使用index.


<div *ngFor="let panel of panels; index as i" class="panel" [id]="'panel-' + panel.id">

    <div>{{ panel.title }}</div>

    <input matInput placeholder="Bezeichnung" [(ngModel)]="panels[i].title" (blur)="showAlert(i)" />

</div>

然后通過傳入索引并使用它來獲取面板標題的長度來觸發(fā)組件中的警報。我在blur這里使用了這個事件。


showAlert(index) {

    const titleLength = this.panels[index].title.length;

    // Call alert with the length of the title here.

}


查看完整回答
反對 回復 2021-11-04
?
達令說

TA貢獻1821條經驗 獲得超6個贊

嘗試這個,


<div *ngFor="let panel of panels; index as i" class="panel" [id]="'panel-' + panel.id">

    <div>{{ panel.title }}</div>

    <input (change)="onChange({{panel.title}})" matInput placeholder="Bezeichnung" [(ngModel)]="panel.title" />

</div>



onChange(title) {

          console.log(title.length);

         })


查看完整回答
反對 回復 2021-11-04
  • 3 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號