akserg / ng2-toasty

Angular2 Toasty component shows growl-style alerts and messages for your app.
MIT License
283 stars 102 forks source link

Use toasty with routing #17

Closed kaanlab closed 8 years ago

kaanlab commented 8 years ago

Can you help me understand how to use toasty with routing. I have route to new user "/user/add" and route to all users "/users" in my app. I want that when i clicked "onSave()" (in user-add.component) will displays the toasty message and redirect to a page with all users (users-list.component). I have this code in user-add.component: onSave(){ this.submitted = true; this.userService.addUser(this.user) .then(() => this.notify.emit('User saved!')) .then(() => this.goBack()) .catch(error => this.errorMessage = error); But it works only on a same page.

akserg commented 8 years ago

Add the ng2-toasty element to above or below the router-outlet in application template:

@Component({
    selector: 'app',
    directives: [Toasty],
    template: `
        <router-outlet></router-outlet>
        <ng2-toasty></ng2-toasty>
    `
})
export class AppComponent {
}
kaanlab commented 8 years ago

So easy, thank you!