简体   繁体   中英

How do I share scope data between states in angularjs using two different ui routers?

Based on this link here How do I share $scope data between states in angularjs ui-router? data is being shared on different states using the same controller. Is it possible to achieve the same thing using different ui-router files though?

I have a project that has two ui-router.js files(they are both on the same domain). So can I bind the data from the parent scope on one state to other states on a different ui-router file?

Use services.Services are singletons, so you can store any variables there.

app.service('sessionService', function($http, settings){
    var that = this;
    this.userSessionData = null;

    this.setUserSessionData = function(sessionData) {
        that.userSessionData = sessionData;
    }

    this.getUserSessionData = function() {
        return that.userSessionData;
    };
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM