angular.js - How to pass variables from one page to another in angularjs.
淡淡烟草味
淡淡烟草味 2017-05-15 17:02:15
0
3
637

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" >
淡淡烟草味
淡淡烟草味

reply all(3)
Ty80

The implementation of

servicefactory 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

PHPzhong

It is safer to temporarily store it in localStorage

PHPzhong

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template