我問了一個(gè)類似的問題。但在這里我的問題有點(diǎn)不同。在表格列中,我有 Slide-Toggle 元素,用戶可以無限時(shí)間將它們?cè)O(shè)為 true 或 false。之后有一個(gè)按鈕,用戶可以提交所有這些真值和假值。在我的 HTML 中,那些 Slide-Toggle 元素來自 for 循環(huán),它是從通知數(shù)組生成的。獲取所有帶有 ID 的滑動(dòng)開關(guān)的值(真、假)的最簡單和最好的方法是什么?正如我提到的,我將提交它們,這就是我想要這樣做的原因。這是我在下面嘗試的HTML<h3>Notifications</h3> <table class="table" id="thetable"> <thead> <tr> <th scope="col">#</th> <th scope="col">Tasks</th> <th scope="col">IsFinished</th> </tr> </thead> <tbody> <tr *ngFor="let not of notifications;" [ngStyle]="{ 'background-color': (not.isFinished ? '#dddddd' : 'white') }" > <th scope="row">{{not.id+1}}</th> <td>{{not.task}}</td> <td> <section class="example-section"> <mat-slide-toggle [id]="not.id" class="example-margin" [color]="color" [checked]="not.isFinished" [disabled]="not.isFinished" (change)="onChange($event)" > </mat-slide-toggle> </section> </td> </tr> </tbody> </table> <div class="row"> <div class="col"> <button mat-raised-button color="primary" (click)="openDialog()">Add Task</button> <button mat-raised-button color="primary" (click)="onSave()">Save</button> </div>TypeScirpt(數(shù)組是怎么來的) ngOnInit() { this.notifications=this.notificationService.getNotifications(); }
如何獲取所有 Slide-Toggle 元素的 ID 和值
慕妹3242003
2021-10-29 16:22:46