【发布时间】:2014-03-06 18:05:09
【问题描述】:
这是我第一次尝试将 Angular 与 Wordpress 结合使用。我想将$location 注入到config 模块中,这样我就可以这样使用它:
app = angular.module 'app', [ 'ngResource', 'ngRoute' ]
app.config [ '$routeProvider', '$location', ( $routeProvider, $location )->
$location.hasPrefix '!'
$location.html5Mode true
]
很遗憾,将$location 或$locationProvider 与config 一起使用会导致Unknown Provider 错误。我已经包含了所有必要的依赖项,即。 angular-route.min.js,但是,它仍然没有正确解决。
如果我删除 $location 它会起作用。
app = angular.module 'app', [ 'ngResource', 'ngRoute' ]
app.config [ '$routeProvider', ( $routeProvider )->
# ROUTES
]
编辑
如果我将 $location 替换为 $locationProvider 我会得到 Failed to instantiate module app due to: TypeError: Object # has no method 'hasPrefix'
【问题讨论】:
-
这可能会对您有所帮助:Inject service in app.config.
-
我会调查的。谢谢。
-
我认为您只能在
config中注入提供程序,并且只能在app.run中注入服务 -
如果我使用
$locationProvider而不是$location,我仍然会收到错误消息