Hi.
I have a problem.
I charge my data from a provider page, but when it is called from a new ts page, the following error is shown
my code:
service page:
import { Injectable } from ‘@angular/core’;
@Injectable()
export class ServicioProvider {
productos: any;
constructor() {
console.log(‘Hello ServicioProvider Provider’);
this.productos = [
{referencia: ‘T34’, producto: ‘URBANFUN’, precio: 34.65 , imagen: ‘…/…/assets/productos/tecnologia/URBANFUN.jpg’},
{referencia: ‘T56’, producto: ‘INSOMNIA-CRANEAL’, precio: 129.35 , imagen: ‘…/…/assets/productos/tecnologia/insomnia-relief-Craneal.jpg’},
{referencia: ‘V09’, producto: ‘TOILETRY-BAG-ORGANIZER’, precio: 15.25 , imagen: ‘…/…/assets/productos/tecnologia/Toiletry-Bag-Organizer.jpg’},
{referencia: ‘V78’, producto: ‘SUITCASE-ELASTIC-LUGGAGE’, precio: 20.00 , imagen: ‘…/…/assets/productos/tecnologia/Suitcase-Elastic-Luggage.jpg’},
{referencia: ‘O88’, producto: ‘ORIGIANL-HK-WATCH’, precio: 125.00, imagen: ‘…/…/assets/productos/tecnologia/Origianl-HK-Watch.jpg’},
{referencia: ‘O90’, producto: ‘CASUAL-BOOTS’, precio: 62.55, imagen: ‘…/…/assets/productos/tecnologia/Casual-Boots.jpg’},
{referencia: ‘T90’, producto: ‘EXTERNAL-BATTERY-CHARGER’, precio:25.45 , imagen: ‘…/…/assets/productos/tecnologia/External-Battery-Charger.jpg’}
];
}
descargarTodo(){
return Promise.resolve(this.productos);
};
ConsegirElementoPorID(id){
for(var i=0; i< (this.productos).length; i++)
{
if(this.productos[i].referencia == id)
{
return Promise.resolve(this.productos[i]);
}
};
}
}
ts. document
import { Component } from ‘@angular/core’;
import { NavController, NavParams } from ‘ionic-angular’;
import { ServicioProvider } from ‘…/…/providers/servicio/servicio’;
import { DetallePage } from ‘…/…/pages/detalle/detalle’;
@Component({
selector: ‘page-busqueda’,
templateUrl: ‘busqueda.html’,
})
export class BusquedaPage {
fecha = new Date();
items: any;
productos: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
public serProvider: ServicioProvider) {
this.initializeItems();
this.serProvider.descargarTodo().then(result => {
this.items = result;
});
}
detallePagina(id){
this.navCtrl.push(DetallePage, {referencia: id});
};
initializeItems() {
this.items = this.productos;
console.log(this.items);
}
getItems(ev: any) {
console.log(this.items);
// Reset items back to all of the items
this.initializeItems();
// captura los datos en la variable
// set val to the value of the searchbar
let val = ev.target.value;
// if the value is an empty string don’t filter the items
if (val && val.trim() != ‘’) {
this.items = this.items.filter((item) => {
return (item.producto.toLowerCase().indexOf(val.toLowerCase()) > -1);
})
}
this.serProvider.descargarTodo().then(result => {
this.items = result;
});
}
ionViewDidLoad() {
console.log(‘ionViewDidLoad BusquedaPage’);
}
}
html.document
<ion-searchbar (ionInput)=“getItems($event)” placeholder=“Buscar…”>
{{item.producto}}
{{item.precio | number:‘1.2-2’ | currency:‘EUR’:true}} €