Hi all,
I can’t find a way the solve this issue.
I’m doing a form that is going to have 10 components.
Until now i did 5 and the last one is not working properly.
Here’s what i’m trying to do:
1 - When the component loads, ngOnInit is fired and it get all the equipment models related to the input “brand_id” from the database.(This step is working)
2 - When the “brand_id” changes value, the function ngOnChanges() is fired and what was supposed to happen was that the function getEquipmentsModel() return the equipment models of this new brand_id.(This step is not working)
The ngOnChanges() is been called and also the function getEquipmentsModel().
The right value of brand_id is been sent to the function that gets data from the database.
The this.daoEquipmentModels.getModelsByBrand() is always returning an empty array.
Am i missing something?
Code of the component:
import {Component, Input, Output, EventEmitter} from '@angular/core';
import {DAOEquipmentModel} from '../../dao/dao-equipment-model';
@Component({
selector: 'equipment-model-select',
templateUrl: 'build/components/equipment-model-select/equipment-model-select.html',
inputs: ['brand_id', 'equipment_model_id'],
outputs: ['changeEquipmentModel']
})
export class EquipmentModelSelect {
constructor() {
this.equipmentModels = [];
this.daoEquipmentModels = new DAOEquipmentModel();
this.changeEquipmentModel = new EventEmitter();
}
ngOnInit(){
this.getEquipmentModels();
}
ngOnChanges(changes){
this.getEquipmentModels();
}
getEquipmentModels(){
this.daoEquipmentModels.getModelsByBrand(this.brand_id, (equipmentModels) => {
this.equipmentModels = equipmentModels;
});
}
Code of the data access object:
import {Storage, SqlStorage} from 'ionic-angular';
export class DAOEquipmentModel {
constructor(){
this.storage = new Storage(SqlStorage);
}
getModelsByBrand(brand_id, successCallback){
this.storage.query("SELECT * FROM models WHERE brand_id = ? ORDER BY name",[brand_id]).then((data) => {
var equipmentModels = [];
for(var i = 0; i < data.res.rows.length; i++){
equipmentModels.push(data.res.rows.item(i));
}
return successCallback(equipmentModels);
});
}
}
Any idea will be helpful, i’m stuck on this since morning.
Thanks