javascript - Save form data in view -
how can save data 1 view in angularjs?
i did $rootscope
from see, use 2 different controllers each view (or 1 view , none root view).
the problem angular can't share data between controllers that.
you either have use service/factory, or use rootscope, not did, rather broadcast
, emit
if use service.
edit here go, service :
(function() { 'use strict'; angular .module('yourmodulename') .factory('countriesservice', countriesservice); countriesservice.$inject = ['your', 'dependencies', 'here', 'in', 'string']; /* @nginject */ function countriesservice(your, dependencies, here, not, in, string) { var service = { setcountries: setcountries, getcountries: getcountries }; var vm = this; vm.countries = []; // or maybe object ? // ... list of other variables need store. return service; //////////////// function setcountries(listofcountries) { vm.countries = listofcountries; } function getcountries() { return vm.countries; } } })();
this store variables. in controller add countriesservice
dependency, save use countriesservice.setcountries
, load use countriesservice.getcountries
. aware refreshing page delete data !
edit number 2 if you're scared of john papa guidelines, here simple service can use in same file put controller :
app.factory('countrycontrol', function(your, dependencies) { var service = { setcountries: setcountries, getcountries: getcountries }; this.countries = []; // or maybe object ? // ... list of other variables need store. return service; //////////////// function setcountries(listofcountries) { this.countries = listofcountries; } function getcountries() { return this.countries; } });
Comments
Post a Comment