search

Home  >  Q&A  >  body text

angular.js - angularjs怎么从一个页面向另一个页面传变量。

本人是新入门的小白,最近在做一个登陆页面。

图中店面从后台动态获取 json id为1,我想把这个id保存之后让另一个页面调用,该怎么写。。。
而且店面不只有一个。。

<select id="CardType" class="form-control"ng-model="site_id" ng-options="a.name for a in names" >
淡淡烟草味淡淡烟草味2745 days ago617

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