Passing object between views (flash message)

前端 未结 3 1632
春和景丽
春和景丽 2021-02-07 12:51

What is the best way to pass message in the below scenario.

In the success scenario of $scope.p.$save, the result contains a message (res.message

相关标签:
3条回答
  • 2021-02-07 12:57

    I don't believe there's a way to do this default to AngularJS. Your best bet would just be passing the message (encoded) through a query string.

    0 讨论(0)
  • 2021-02-07 13:00

    You could use a service which displays the flash on $routeChangeSuccess.

    Each time you set a flash message, add it to a queue, and when the route changes take the first item off the queue and set it to the current message.

    Here's a demo:

    http://plnkr.co/edit/3n8m1X?p=preview

    0 讨论(0)
  • 2021-02-07 13:08

    I was looking to implement similar functionality, but actually wanted more of a growl style message.

    I've updated the excellent plinkr code that Andy provided above to include a 'pop' method that leverages the toastr growl-style notification library.

    My update also lets you to specify the notification type (info, warning, success, error) and title.

    The 'pop' method skips adding the message to the queue, and instead pops it up on the screen immediately. The set/get functionality from Andy's previous plinkr remains mostly unchanged.

    You can find my update here: http://plnkr.co/edit/MY2SXG?p=preview

    0 讨论(0)
提交回复
热议问题