Carlos Salazar
Carlos Salazar

Reputation: 1898

Build a js object in a multipage form ionic

I want to build an js object using a multi-view form, so for example i have 3 views

i did this way because the form is large,so the user may feel the form is infinite...

the final obj should be like this

{
      //basic data
      attr1 : string,
      attr2 : string,
      attr3 : string,
      //category data
      attr4 : number,
      attr5 : [...],
      attr6 : string,
      //sell data
      attr7 : number,
      attr8 : [...],
}

the numbers of field may vary.

what i want to know if i can initialize the obj in a provider or something and use it later on each view?

if it is possible, how do i call it in each view?

how can i retrieve the obj?

im using ionic2

Upvotes: 0

Views: 17

Answers (1)

Toby Okeke
Toby Okeke

Reputation: 654

Yes it is. Create a property of the provider and update that property as the form is being filled on each page.

private data:any;
constructor(private dataProiver:DataProvider){}
getData(){
    this.data = this.dataProvider.dataPropertyName;
}
saveData(){
    this.dataProvider.dataPropertyName = this.data; // the data would contain the object with more data in it
}

You import the created data provider and use in the manner above for each page.

Upvotes: 1

Related Questions