search

Home  >  Q&A  >  body text

angular.js - How to pass variables from one page to another in angularjs.

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

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 17:04:15

    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

    reply
    0
  • PHPz

    PHPz2017-05-15 17:04:15

    It is safer to temporarily store it in localStorage

    reply
    0
  • PHPz

    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.

    reply
    0
  • Cancelreply