我尝试在加载任何页面时使用 Angular-toaster。 例如 - 我有两个页面客户添加和客户列表,我的要求是当我添加任何新客户时在客户列表页面上显示 toastr 。
这是我的代码:saveCustomer 回调中的代码
this.$state.go('app.Customers', { Msg: d.Message });
客户列表页面中的代码: html:
<toaster-container toaster-options="{'position-class': 'toast-top-right', 'close-button':true}"></toaster-container>
JS:
static $inject=['toaster']
constructor( private toaster: any){
if (this.$stateParams.Msg !== null)
this.msgToClient = this.$stateParams.Msg;
this.toaster.pop('success', 'Success', this.msgToClient);
}
我在客户列表页面上没有看到此消息。 但我可以在 (click) 等事件中看到 toastr 消息。我尝试了很多方法但没有成功。
最佳答案
我已经遇到过这个问题了。我知道这不优雅,但我这样解决了:
setTimeout(function(){
toaster.pop('success', 'Success', 'Page Load');
$scope.$apply();
}, 100);
关于angularjs - 当我调用构造函数时, Angular 1 toastr 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45701585/