【问题标题】:Use of $rootScope value module.config throwing error使用 $rootScope 值 module.config 抛出错误
【发布时间】:2015-10-28 11:11:10
【问题描述】:

这是我的 app.config

  app.config(['$translateProvider',function ($translateProvider) {

      $translateProvider.useUrlLoader('/api/sitecore/translations/get?pageName=' + $rootScope.currentPage + '&');
}

当我运行它时,我得到了错误

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.3/$injector/modulerr?p0=appModule&p1=Refere…%20at%20Zd%20(http%3A%2F%2Fathlonpoc%2Fscripts%2Fangular.min.js%3A18%3A464)(anonymous function) @ angular.min.js:6(anonymous function) @ angular.min.js:38m @ angular.min.js:7g @ angular.min.js:37eb @ angular.min.js:40d @ angular.min.js:19Ac @ angular.min.js:20Zd @ angular.min.js:18(anonymous function) @ angular.min.js:289a @ angular.min.js:176c @ angular.min.js:35

请帮帮我..我是 angularJs 的新手

【问题讨论】:

  • 你不能在config阶段注入东西:stackoverflow.com/questions/22682753/…
  • @SergiuParaschiv 好吧,你可以,但只有常量和提供者:)
  • 请告知是否有任何其他方法可以使该网址动态化。
  • @sp00m:是的,你是对的。

标签: angularjs angularjs-scope angularjs-rootscope


【解决方案1】:

您正在代码中使用 $rootScope,但您尚未注入此依赖项。

app.config(['$translateProvider',function ($translateProvider,$rootScope) {

      $translateProvider.useUrlLoader('/api/sitecore/translations/get?pageName=' + $rootScope.currentPage + '&');

}

【讨论】:

    猜你喜欢
    • 2018-11-14
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2011-06-10
    • 2012-10-28
    相关资源
    最近更新 更多