I am a newbie and I am currently working on a landing page.
The store in the picture dynamically obtains the json id from the background as 1. I want to save this id and call it on another page. How should I write it? . .
And there is more than one store. .
<select id="CardType" class="form-control"ng-model="site_id" ng-options="a.name for a in names" >
PHP中文网2017-05-15 17:04:15
The implementation of
service
和factory
is all singleton, just write one and save it. Use it elsewhere:
app.service('TmpService', function(){
var currentId;
this.cacheId = function(id){
currentId = id;
};
this.getId = function(){
return currentId;
};
});
Although it is not very beautiful, it can solve your problem
PHPz2017-05-15 17:04:15
I don’t know if you are making a single-page application. I think you need routing here, take a look at angular's ui router https://scotch.io/tutorials/3-simple-tips-for-using-ui-router.
If it is not a single page, this ID should be passed to the background when jumping and let the background handle it.
If none of the above are true, you can use localStorage, cookie or you add this ID to the url, and then use js to get the new page, but it is not recommended.