【问题标题】:How to get ionic rootScope on config stateprovider?如何在配置 stateprovider 上获取离子 rootScope?
【发布时间】:2016-09-13 12:15:01
【问题描述】:

如何在下面的行中检索$rootScope 值?

.config(function($stateProvider, $urlRouterProvider) {  
  $stateProvider
  // Here is where I need to get the value of $rootScope.
}

【问题讨论】:

  • config(configuration) 阶段$rooScope(scope) 的应用程序尚未创建,所以你不能在那里获得$rootScope,你可以使用.run 阻止你可以注入和使用$rootScope
  • 你能举个例子吗?谢谢
  • .run(function($rootScope){ /* use $rootScope here */ })

标签: javascript android html angularjs ionic-framework


【解决方案1】:

这就是我在配置模块中使用离子弹出服务的方式

在你的配置函数中注入 $ionicPopupProvider

然后做这样的事情

 $ionicPopupProvider.$get().alert({
                  title: 'Alert',
                  template: "Something went wrong on Server Side"
                });

同样可以用于rootscope,注入rootScopeProvider并使用它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    • 1970-01-01
    • 2015-09-03
    • 2018-04-27
    • 1970-01-01
    相关资源
    最近更新 更多