本人是新入门的小白,最近在做一个登陆页面。
图中店面从后台动态获取 json id为1,我想把这个id保存之后让另一个页面调用,该怎么写。。。
而且店面不只有一个。。
<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.