Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
Restablecer los valores de ngModel en ngIf en angular2

Tengo un modelo que es un elemento de matriz. Quiero borrar los valores de cada elemento en la condición ngIf. Encuentre a continuación el HTML:

 <div *ngIf="flag" > <table id="table" class="table table-hover table-bordered table-mc-light-blue"> <thead> <tr> <th>col 1</th> <th>col 2</th> </tr> </thead> <tr *ngFor="let item of collection;"> <td>{{item.col1}}</td> <td> <input type="text" class="form-control" [(ngModel)]="item.col2" #input="ngModel" name="input-{{i}}"> </td> </tr> </table> </div>

En el indicador establecido en falso, quiero borrar todos los valores de la colección . Hay una opción para inicializar la colección , pero no quiero hacerlo ya que tengo varias colecciones de este tipo.

Cualquier ayuda sería apreciable!!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

<input type="radio" (change)="resetForm()"/> resetForm(){ if(!this.flag){ this.collection = new Array() } }
over 4 years ago · Santiago Trujillo Report

0

¿Cuál es el "evento" o la llamada al método que hace que el indicador se establezca en falso?

Esta es la llamada al método donde también querrá borrar la colección.

Algo como esto:

 public toggleFlag() { this.expandFlag = !this.expandFlag; this.collection = []; }
over 4 years ago · Santiago Trujillo Report

0

En su componente:

 ngDoCheck() { if (!this.flag) { this.collection = []; } }

Y tienes que implementar DoCheck así:

 export class myClass implements OnInit, DoCheck {

Básicamente, este es un oyente que se activa con cada cambio que ocurre, y aquí verificamos que this.flag sea falso y vaciamos el elemento de la matriz de collection .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!