was playing around a bit more to refresh myself for a class I am teaching and I modified your code to use ngResource
instead of $http
.
I also moved the model code out into the service you started to create… The service was abit tricky since you are using jsonp
but there is definitely a way to manage that with ngResource
.factory('myService', function($resource) {
var savedData = {}
function set(data) {
savedData = data;
}
//
//
function _get(_id) {
console.log("_get(_id) " + _id);
var baseUrl = 'http://quedadas.magentadesigncorporation.com/quedadas/getUsersQdd/idquedada/:id/format/json';
var itemResource = $resource(baseUrl, {
id: _id ,
callback: "JSON_CALLBACK"
},{
get : {
method :"JSONP"
}
});
var item = itemResource.get();
item.$promise.then(function (data) {
// do something with the data
console.log(data);
return data;
}, function(_error){
console.log(_error)
});
return item.$promise;
}
/**
*/
function _query(_options) {
var baseUrl = 'http://quedadas.magentadesigncorporation.com/quedadas/getActiveQdd/iduser/' + ':id/fecha_actual/:fecha/hora/:hora/format/json';
var productsResource = $resource(baseUrl, {
id: _options.iduser ,
fecha: _options.fecha_actual,
hora: _options.hora,
callback: "JSON_CALLBACK"
},{
query : {
method :"JSONP",
isArray : false
}
});
var products = productsResource.query();
products.$promise.then(function (data) {
// do something with the data
console.log(data);
return data;
}, function(_error){
console.log(_error)
});
return products.$promise;
}
return {
set: set,
get: _get,
query : _query
}
});
And finally I added $stateParams
to the detail page to more efficiently retrieve the selected item
.state('app.detail', {
url: '/detail/:id',
views: {
'menuContent': {
templateUrl: 'templates/detail.html',
controller: 'QddCtrl'
}
}
});
get the parameter in the controller
.controller('QddCtrl', function($scope, myService, $stateParams) {
myService.get($stateParams.id).then(function(_data){
$scope.qdd = _data.result[0];
console.log('Players to Qdd: ', $scope.qdd);
}, function(_error){
alert("error " + _error);
})
})
http://codepen.io/aaronksaunders/pen/gbWgQe?editors=101