我收到以下错误:未知提供商:BackandProvider< - Backand< - 发布 这是我的代码: 在index.html中,我包含了backand.min.js:
<script src="https://cdn.backand.net/backand/dist/1.8.2/backand.min.js"></script>
我有一个带有find方法的工厂帖子。 Factory.js
app.factory('Post',["$http","$q","Backand", function($http, $q, Backand){
var factory = {
posts : false,
find : function(options){
var deferred = $q.defer();
$http({
method: 'GET',
url: Backand.getApiUrl() + '/1/objects/' + options.name,
params: {
pageSize: 20,
pageNumber: 1,
filter: options.filter || '',
sort: options.sort || ''
}
})
.success(function(data,status){
factory.posts = data;
deferred.resolve(factory.posts);
}).error(function(data,status){
deferred.reject('Impossible de récupérer les articles'+ status);
})
return deferred.promise;
},
get : function(id){
var deferred = $q.defer();
var post = {};
var posts = factory.find().then(function(posts){
angular.forEach(posts,function(value,key){
if(value.id == id){
post = value;
}
});
deferred.resolve(post);
}, function(msg){
deferred.reject(msg);
});
return deferred.promise;
},
add : function(comment){
var deferred = $q.defer();
deferred.resolve();
return deferred.promise;
}
};
return factory;
}]);
在我的控制器中,我调用了我工厂的find方法。 Controller.js
app.controller('PostsCtrl',["$scope","$rootScope","Post", function($scope, $rootScope,Post){
$rootScope.loading = true;
var options = {name:"Post",filter:"",sort:""}
$scope.posts = Post.find(options).then(function(posts){
$rootScope.loading = false;
$scope.posts = posts;
}, function(msg){
alert(msg);
});
}]);
配置如下。 app.js
var app = angular.module('monApp',['ngRoute','ngResource','backand']);
app.config(["$routeProvider","BackandProvider",function($routeProvider, BackandProvider){
$routeProvider
.when('/',{templateUrl:'partials/home.html',controller:'PostsCtrl'})
.when('/comments/:id', {templateUrl: 'partials/comments.html',controller:'CommentsCtrl'})
.otherwise({redirectTo : '/'});
BackandProvider.setAppName('APP-NAME');
BackandProvider.setSignUpToken('TOKEN');
BackandProvider.setAnonymousToken('ANONYMOUS-TOKEN');
}]);