这是我第一次尝试在Wordpress中使用Angular。我想注入$location
到config
模块,所以我可以这样使用它:
app = angular.module 'app', [ 'ngResource', 'ngRoute' ]
app.config [ '$routeProvider', '$location', ($routeProvider, $location)->
$location.hasPrefix '!'
$location.html5Mode true
]
不幸的是,使用$location
或$locationProvider
与config
造成未知提供程序错误。我已经包含了所有必要的依赖关系,即。 angular-route.min.js
,但是,它仍然没有正确解决。
如果我删除$location
它的作品。
app = angular.module 'app', [ 'ngResource', 'ngRoute' ]
app.config [ '$routeProvider', ($routeProvider)->
# ROUTES
]
编辑
如果我$locationProvider
取代$location
我得到,如果你使用的名称$locationProvider
可以注射的名字Failed to instantiate module app due to: TypeError: Object # has no method 'hasPrefix'
这可以帮助你:在注射服务的app.config(http://stackoverflow.com/questions/15937267/inject-service-in -app-CONFIG)。 – PrimosK
我会研究一下。谢谢。 –
我认为你只能在'config'中注入提供者,并且只在'app.run'中提供服务 – doodeec