Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
Working with Angular-13 using models . can model.ts file have images as a property?

Can a .model.ts file have a class with a property as an image. and later use it using string interpolation? or is there a better way to deal with this? string interpolation ( BEGINNER ANGULAR TRYING OUT THINGS!!)

Eg:-

Products. model.ts

 export class Products {
 name : string;
 description: string;
 price : number;
 **image  : ??**

constructor(name:string,description:string,price:number,**image:??**){
    this.name = name;
    this.description = description;
    this.price = price;
}

}

Product. component.ts

productsList: Products[]=[
    new Products('IphoneX','this is an IphonX product',800),
    new Products('IphoneXL','this is an IphonXl product',900),
    new Products('IphoneXmini','this is an IphonXmini product',1200),
    new Products('IphoneXpromax','this is an IphonXpromax product',1340),
  ]

product.component.html

<div class="card__container" *ngFor="let product of productsList">
    <mat-card>
        <div class="product" >
            <div class="product__img" >
                {{ product.img }}
            </div>
            <div class="product__details">
                <h1>{{ product.name}}</h1>
                <p>{{ product.description }}</p>
                <h3>{{ product.price | currency }}</h3>
                <button (click)="addtoCart(product)"><mat-icon>add_shopping_cart</mat-icon>Cart</button>
            </div>
        </div>
        
    </mat-card>
</div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The easiest solution would be to do:

image: 'some_image_name.png'

(or for class: image: string)

then have that image in assets folder (for example in assets/images), so that you can reference it from the template as:

<div class="product__img" >
    <img [src]="'/assets/images/' + product.img" />
</div>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda