my goal achieve is:
first insert new database record http post, resolve stateprovider , grab new id , change view , stateparams.
i have code http post service
myapp.service('postservice', ['$http', function($http) { this.insertnew = function() { $http.post('create_new.php') .success(function(data) { return data; }); }; create_new.php returns id (it works, proved console)
return json_encode($data); and stateprovider looks (section)
$stateprovider .state('newrecord', { resolve: { newartid: ['postservice', function(postservice) { return postservice.insertnew(); }] }, params: { artid: <-- new id db }, i did tests stateparams in serval variations (in resolve , params). how can bring new id stateparams, can access views?
thanks help!
i'm not sure oder of operations correct. params when already have data. should return data resolve, can access in scope, ex:
service:
.service('postservice', function ($http) { this.insertnew = function () { return $http.post('create_new.php').then(function (data) { return data; }); } }) route:
$stateprovider .state('newrecord', { views: { "main": { controller: 'somectrl', templateurl: '...' } }, resolvedid: { newartid: function (postservice) { return postservice.insertnew().then(function (response) { return response; }); } } }) controller:
.controller('somectrl', function (resolvedid) { var newid = resolvedid.id; //depending on returned });
Comments
Post a Comment