this.jind
this.jind

Reputation: 349

Ionic 4, passing data between one file.ts to another file.ts?

how do I pass some data between pages in Ionic 4? Consider this example: In file1.ts I have:

export class ArchivePage{

 constructor() { }
 messages = [
    {
      user: 'user1',
      msg: 'Hello!',
      type: 0
    },
    {
      user: 'user2',
      msg: 'Hi!',
      type: 1
    }
   ];
}

Now in file1.html I can simply use *ngFor = "let message of messages" and {{message.user}} {{message.msg}}. But I have another file2.ts, how can I pass this messages to file2.ts in order to use them in file2.html?

Thanks a lot

Upvotes: 0

Views: 330

Answers (1)

Emad Abdou
Emad Abdou

Reputation: 287

You have two options, you can use a shared service for your data as data source and get data from it in the ts files, or you can use Storage for setting your messages in one ts file and retrieve it in the second file, for more details for the second solution, please check the attached documentation link https://ionicframework.com/docs/angular/storage

Upvotes: 1

Related Questions