Sunday 15 March 2015

javascript - AngularJS ui-router resolve does not return custom value -



javascript - AngularJS ui-router resolve does not return custom value -

when trying resolve info before moving page, forcefulness resolve promise, convert custom object , seek homecoming custom object resolve object.

.state("trip.detail", { url: '/:tripid', templateurl: 'partials/trip/detail.html', controller: 'tripdetailcontroller', resolve: { traindata: function (tripservice, $stateparams, $q) { homecoming tripservice.gettripbyid($stateparams.tripid,function (data) { console.log("received: " + data); homecoming { "relativetrainid": data.trainid, "from": new date(data.departure).toisostring(), "to": new date(data.arrival).toisostring(), "projectid": data.projectid, "istrip": true, "tripid": data.id, "trajectory": data.trajectory, "statistics": data.statistics } }).$promise; } } });

this works, except 'traindata' beingness injected controller actualy value 'data' , not custom 1 create.

what's going on?

extra info tripservice:

services.factory('tripservice', function ($resource) {

function tripservice() { this.tripresource = $resource('rest/trip/:tripid'); } tripservice.prototype.gettrips = function (start, end, project, trainids, callback) { homecoming this.tripsresource.query({ projectid: project, trainids: trainids, from: start, to: end }, callback) } tripservice.prototype.gettripbyid = function (tripid, callback) { homecoming this.tripresource.get({ tripid: tripid }, callback); } homecoming new tripservice();

});

you have create own promise , resolve custom object:

.state("trip.detail", { url: '/:tripid', templateurl: 'partials/trip/detail.html', controller: 'tripdetailcontroller', resolve: { traindata: function (tripservice, $stateparams, $q) { var deferred = $q.defer(); tripservice.gettripbyid($stateparams.tripid,function (data) { console.log("received: " + data); deferred.resolve({ "relativetrainid": data.trainid, "from": new date(data.departure).toisostring(), "to": new date(data.arrival).toisostring(), "projectid": data.projectid, "istrip": true, "tripid": data.id, "trajectory": data.trajectory, "statistics": data.statistics }); }); homecoming deferred.promise; } } });

javascript angularjs

No comments:

Post a Comment