Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have newline character in Ionic2 toast?

I tried both \n and < br/ >, but unfortunately not working!

Is this Possible ?

//Displaying toast to welcome user!
let user = this.currentUser();
//console.log(user);
let toast = Toast.create({
  message: 'Hi ' + user.email + '! <br/> Welcome to My App',
  duration: 5000,
  position: 'bottom'
});

toast.onDismiss(() => {
  console.log('Dismissed toast');
});

this.nav.present(toast);
like image 212
Ankit Maheshwari Avatar asked Jul 26 '16 18:07

Ankit Maheshwari


2 Answers

Actually it IS possible. You can do the following:

.toast-message {
  white-space: pre;
}

and \n for a line-break.

Note: Take a look at home.ts and style.css.

See working plunkr

like image 139
Ben Kauer Avatar answered Sep 21 '22 09:09

Ben Kauer


Although @iWork solution works for many situation but if you have close button in your toast it will be pushed out of screen.

So you can use these style sheet instead:

.toast-message {
  white-space: pre-line;
}

p.s you need to use \n for line break in your string

like image 26
Reza Avatar answered Sep 19 '22 09:09

Reza