angular.module("app", ["kendo.directives"])
.controller("news", function($scope,newsService) {
var dataSource = new kendo.data.DataSource({
transport: {
read: dataSourceRead
}
});
function dataSourceRead(options){
//todo: show loading
newsService.getByCategory($scope.selectedCategory.value)
.then(
function(response){
options.success(response);
//todo: hide loading
},
function(response){
options.error(response);
//todo: handle errors.
});
}
$scope.newsListViewOptions = {
dataSource: dataSource
};
})
.service('newsService', function($q, $http) {
this.getByCategory = function(category){
var url = "your url";
var request = $http({
method: "jsonp",
url: url
});
return( request.then( handleSuccess, handleError ) );
};
function handleError( response ) {
//if no message return from server
if (
! angular.isObject( response.data ) ||
! response.data.message
) {
return( $q.reject( "An unknown error occurred." ) );
}
return( $q.reject( response.data.message ) );
}
function handleSuccess( response ) {
return( response.data );
}
});
相关