Wednesday, 15 January 2014

angularjs - data from one angular call method to another method as parameter -



angularjs - data from one angular call method to another method as parameter -

the next code structure, iam using hot towel template mvc project.

the script:

(function () { 'use strict'; var controllerid = 'editemployeecontroller'; angular.module('app').controller(controllerid, ['common', 'employeeservice', employeedata]); function employeedata(common, employeeservice) { var getlogfn = common.logger.getlogfn; var log = getlogfn(controllerid); var $filter = common.$filter; var logerror = common.logger.getlogfn('app', 'error'); var vm = this; vm.countrycode; vm.country = []; vm.state = []; vm.employeeinfo = {}; //calling method employee info activate(); //calling methods states getstates(); function activate() { var promises = [getemployeeinfo(),getstates()]; common.activatecontroller(promises, controllerid) .then(function () { }); } } function getemployeeinfo() { homecoming employeeservice.getempinfoforedit(personid).then(function (data) { vm.countrycode = data.country; homecoming vm.employeeinfo = data; } function getstates() { homecoming employeeservice.getstates(vm.countrycode).then(function (data) { homecoming vm.state = data; } } })();

employeeservice.js

code snippet employeeservice.js

function getempinfoforedit(personid) { var empinfoforedit = $resource('employee/getemployeedetailsforedit', angular.fromjson(personid), { 'query': { method: 'post', isarray: false } }); var deferred = $q.defer(); empinfoforedit.query({}, function (response) { deferred.resolve(response); }, function (error) { deferred.reject(error); }) homecoming deferred.promise; }

vm.countrycode shows null, though assigning value in getemployeeinfo method.because unable states.

please allow me know can info vm.countrycode ?

(function () { 'use strict'; var controllerid = 'editemployeecontroller'; angular.module('app').controller(controllerid, ['common', 'employeeservice', employeedata]); function employeedata(common, employeeservice) { var getlogfn = common.logger.getlogfn; var log = getlogfn(controllerid); var $filter = common.$filter; var logerror = common.logger.getlogfn('app', 'error'); var vm = this; vm.countrycode=[]; vm.country = []; vm.state = []; vm.employeeinfo = {}; //calling method employee info activate(); //calling methods states getstates(); function activate() { var promises = [getemployeeinfo(),getstates()]; common.activatecontroller(promises, controllerid) .then(function () { }); } } function getemployeeinfo() { homecoming employeeservice.getempinfoforedit(personid).then(function (data) { vm.countrycode = data.country; homecoming vm.employeeinfo = data; } function getstates() { homecoming employeeservice.getstates(vm.countrycode).then(function (data) { homecoming vm.state = data; } } })();

angularjs asp.net-mvc-4 hottowel

No comments:

Post a Comment