Basic List Produtcs on Angular2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="cd-gallery"> | |
<li *ngFor="let tienda of tiendas" class="restaurante-item"> | |
<a href=""> | |
<ul class="cd-item-wrapper"> | |
<li class="selected"> | |
<img src="http://localhost/slim/uploads/alphanet_png-01.png" alt="Preview image" *ngIf="tienda.imagen && tienda.imagen !== 'null'" > | |
</li> | |
<li class="move-right" data-sale="true" data-price="$22"> | |
</li> | |
<li> | |
</li> | |
</ul> <!-- cd-item-wrapper --> | |
</a> | |
<div class="cd-item-info"> | |
<b><a href="#0"> {{tienda.nombre}}</a></b> | |
<em class="cd-price">{{tienda.precio}}</em> | |
</div> <!-- cd-item-info --> | |
</li> | |
</ul> <!-- cd-gallery --> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { Router, ActivatedRoute, Params } from "@angular/router"; | |
import { TiendaService } from "../../services/tienda.service"; | |
import { Tienda } from "../../model/tienda" | |
import initDemo = require('../../../assets/js/charts.js'); | |
@Component({ | |
moduleId: module.id, | |
selector: 'home-cmp', | |
templateUrl: 'home.component.html', | |
providers: [TiendaService] | |
}) | |
export class HomeComponent implements OnInit { | |
public tiendas: Tienda[]; | |
public titulo: string; | |
public status: string; | |
public errorMessage; | |
public confirmado; | |
constructor( | |
private _route: ActivatedRoute, | |
private _router: Router, | |
private _tiendaService: TiendaService | |
) { | |
} | |
ngOnInit() { | |
this.getTiendas(); | |
console.log("Tienda-listas cargado"); | |
} | |
getTiendas() { | |
this._tiendaService.getTiendas() | |
.subscribe( | |
result => { | |
this.tiendas = result.data; | |
this.status = result.status; | |
if (this.status !== "success") { | |
alert("Error conectando con la api!!!") | |
} | |
else { | |
} | |
}, | |
error => { | |
this.errorMessage = <any>error; | |
if (this.errorMessage != null) { | |
console.error(this.errorMessage); | |
alert("Error en la peticion"); | |
} | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment