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

186
Views
Angular2 verifica si el objeto tiene personas dentro de * ngIf
export interface Element { name: string; } export class Room implements Element { name: string; type:string } export class Hall implements Element { name: string; }

y mi tipo de variable es como a continuación

 selectedElement: Element;

ahora en html, ¿cómo puedo verificar si el objeto tiene la propiedad 'tipo' o no?

 <div *ngIf="selectedElement?.type"> my div </div>
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Supongo que esto debería hacer lo que quieres:

 *ngIf="hasProp(selectedElement, 'type')"
 hasProp(o, name) { return o.hasOwnProperty(name); }
about 4 years ago · Santiago Trujillo Report

0

Puedes hacerlo simplemente en el html:

 <div *ngIf="selectedElement.hasOwnProperty('type')"> my div </div>

o

 <div *ngIf="selectedElement.hasOwnProperty('type');then showMyDiv">...</div> <ng-template #showMyDiv> my div </ng-template>
about 4 years ago · Santiago Trujillo Report

0

además de lo dicho por Günter Zöchbauer :

 *ngIf="selectedElement && selectedElement['type']"
about 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!