工厂
angular.module('SearchApp')
.factory('queryFactory', ['$http', function($http) {
var urlBase = 'http://localhost:9002/v1/search?rs:q=oil';
var queryFactory = {};
queryFactory.getQueryResults = function () {
$http.defaults.headers.common['Authorization'] = 'Basic' + btoa('admin' + ':' + 'admin');
return $http.get(urlBase + '&rs:searchCategory=allegro');
};
控制器
angular.module('SearchApp')
app.controller('SearchResultsController', ['$scope', 'queryFactory', function ($scope, queryFactory) {
$scope.status;
$scope.searchResults;
getQueryResults();
function getQueryResults() {
queryFactory.getQueryResults()
.success(function (data) {
$scope.searchResults = data;
})
.error(function (error) {
$scope.status = 'Unable to load search results: ' + error.message;
});
}
}]);