这是我第一次尝试将Angular与Wordpress一起使用。我想将$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
]
如果我将$location
替换为$locationProvider
,我会Failed to instantiate module app due to: TypeError: Object # has no method 'hasPrefix'
答案 0 :(得分:1)
如果您使用名称$locationProvider
作为注射剂的名称,似乎没问题。
和js:
angular.module('myApp', ['ngResource', 'ngRoute'])
.config(function($routeProvider, $locationProvider) { // provider-injector
$locationProvider.hasPrefix = '!';
$locationProvider.html5Mode = true;
});
供Docs参考:
配置块 - 在提供商注册期间执行 和配置阶段。只能注入提供者和常量 到配置块。这是为了防止意外实例化 服务完全配置之前的服务。
答案 1 :(得分:0)
错误是一个简单的错字。
$location.hasPrefix('!');
应该是
$location.hashPrefix('!');