我正在按照this gitcode和google ng-conf为我的应用创建api提供程序。但这是在我的应用程序中覆盖$ routeProvider。当我在控制台中检查$ routeProvider时(在app config中)它只给我apiProvider的实例。为什么会这样? $ routeProvider和apiProvider如何同时使用?请参阅this gitcode和以下代码..
websiteApp.provider('customApi',
function() {
var baseRoute = '';
this.endpoints = {};
this.setBaseRoute = function(route) {
this.baseRoute = route;
};
this.endpoint = function(name) {
var endpointConfig = new ApiEndpointConfig();
this.endpoints[name] = endpointConfig;
return endpointConfig;
};
this.$get = ['$injector', function($injector) {
console.log("$get");
var api = {};
var self = this;
angular.forEach(this.endpoints,
function(endpointConfig, name) {
api[name] = $injector.instantiate(ApiEndpoint, {
baseRoute: self.baseRoute,
endpointConfig: endpointConfig
});
});
return api;
}];
});
websiteApp.config(['FacebookProvider', 'customApiProvider', '$routeProvider',
function ($routeProvider, customApiProvider, FacebookProvider) {
customApiProvider.setBaseRoute('/api/v0/');
$routeProvider
.when('/search',
{
templateUrl: 'assets/angular/widgets/partials/search.html'
})
.when('/',
{
templateUrl: 'assets/angular/widgets/partials/recommendations.html'
});
var myAppId = APPID;
FacebookProvider.setAppId('myAppId');
FacebookProvider.init(myAppId);
}]);
答案 0 :(得分:1)
如果编写缩小的安全代码而不是使用ngmin,则参数顺序必须与字符串顺序匹配。