0

I want to add firebase observable list to variable array in ionic2

I query my template with service :

getModel(model){

    let modelQuery = this.afo.database.list(this.currentUser.username + '/models', {
        query: {
            orderByChild: 'name',
            equalTo: model
        }
    });

    return modelQuery;
}

I call getModel service in my ts :

this.character = navParams.get('character');
this.currentUser = modelService.currentUser;
this.models = modelService.models;
this.model = modelService.getModel(this.character.model);
this.items = this.model;

and I parse data in my page :

<ion-item  *ngFor="let item of items | async">
    {{ item?.items | json }}
</ion-item>

and the result is :

result

my firebase :

enter image description here

my problem is :

I want add to this observable list in my item variable like an array. When I use ngfor for my items I have an inline result with objects in an array

[
{
  "name": "description",
  "rows": "3",
  "type": "ion-textarea"
},
{
  "name": "toggle",
  "type": "ion-toggle"
},
{
  "max": 100,
  "min": 0,
  "name": "range test",
  "type": "ion-range",
  "value": 0
},
{
  "max": 80,
  "min": 0,
  "name": "range 2",
  "type": "ion-range",
  "value": 0
},
{
  "max": 50,
  "min": 0,
  "name": "range 3",
  "type": "ion-range",
  "value": 0
},
{
  "name": "azeazraze",
  "type": "ion-input"
},
{
  "name": "ertefer",
  "type": "ion-title"
},
{
  "name": "ghg",
  "type": "ion-title"
}
]

so I want to add this array in my variable item to show with an ngfor.

3
  • you mean you want to show ionic components in template based on your arraylist? Commented May 2, 2017 at 4:14
  • yes, i want take chikd node on firebase /user/model/items and show it like an array Commented May 2, 2017 at 5:50
  • You will have to make an elaborate template with a lot of *ngIfs. Ionic does not have any real support for server side rendering of templates..if that is what you require Commented May 2, 2017 at 6:14

2 Answers 2

1
A small modification to your query to get items array. 

 getModelItems ( model ) {

    let items = []

    let modelQuery = this.afo.database.list(this.currentUser.username + '/models', {

      query: {
        orderByChild: 'name',
        equalTo: model
      }
    }).subscribe(models => {
      items = [];
      models.forEach(model => {
        items.push(model.items);
      })
    });

    console.log("model query");
    console.log(modelQuery);
    return items;
}
Sign up to request clarification or add additional context in comments.

Comments

0

[code]getModel(model){

let modelQuery = this.afo.database.list(this.currentUser.username + '/models' , {

query: { orderByChild: 'name', equalTo: model

 }}).map((items) => {
   return items.map(item => {
     item.data = this.afo.database.list(this.currentUser.username + `/models/${model.items}` );
     console.log("item",item); 

     return   item; //need this data item in variable
   })
 })

return modelQuery

}[/code]

i use this map, so i need to retrieve this data.item to my page

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.