O
O
Oleg46152017-08-12 12:13:46
Angular
Oleg4615, 2017-08-12 12:13:46

How to work with api on angularJS?

The question is: for the application to work with Api, you need to request a session and insert it into each subsequent application request, the problem is that I cannot make the session request come before the entire application works. that is, the application sends new requests while the session has not yet arrived.
I don’t think it’s difficult, but I’m dumb, tell me some working trick.
and the assignment to the rootScope.sessionId variable does not work yet,
although there is a return in sessionFactory.newSession() ..

angular.module('app',[])
.run(function($rootScope, sessionFactory){
    $rootScope.SessionId=sessionFactory.newSession();
setInterval(function(){
    console.log($rootScope.sessionId);
}, 200 );

})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0X12eb, 2017-08-15
@Oleg4615

1. Use middleware
to control the request pipeline 2. Avoid using $rootScope, use vanilla localStorage to store the variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question