【问题标题】:$rootScope in onExit$rootScope 在 onExit
【发布时间】:2018-07-09 08:01:16
【问题描述】:

当状态改变时,我想在onExit 中使用$rootScope.$broadcast()

但是为此,我需要在.config()中注入$rootScope,这在angular中是不可能的

 onExit: function () {
                //onExit is executed when we leave that state and go to another
                $rootScope.$broadcast('broadCastCloseModalStr');
            }

有人可以帮我实现吗?

【问题讨论】:

  • 你能扩展你的问题并描述你是如何使用模态的吗?大多数模态都被解析为 Promise(在关闭它们时解析/拒绝)
  • @varun 你能添加更多代码并解释你想要做什么吗?

标签: angularjs angular-ui-router angularjs-scope rootscope


【解决方案1】:

使用$injector$rootScope 注入到onExit 中,就像这样

onExit: function($injector) {
    var rootScope = $injector.get('$rootScope');
    console.log("onExit: ", rootScope);
}

但是,这也应该有效

onExit: function($rootScope) {
    console.log("$rootScope: ", $rootScope)
}

这是一个有效的plunk

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多