There are a lot of unknowns here, but yes a service seems like the right
answer.
Basically you'll inject the service into both of your controllers and then
update a value in the service from controllerB. Then in controller a you
should have a watch on that service value and update according when it
changes.
Simple service implementation
angular.module('services.auth', [])
.service('AuthService', function() {
return {
loggedIn: false
};
});
Although I would also suggest moving what ever you are doing in controller
be that is interacting with the server to the service as well. Keep $http
out of your controllers.
Gordon
On Wednesday, June 18, 2014 9:08:53 AM UTC-5, Masoud gheisari wrote:
>
> Hi everyone,
>
> I have checked some of the topics for this matter and i got an
> understanding of controllers are there to initiate scope and i need to use
> services for this matter but i dont know how.
>
> so here is the problem. i have index page which body has only one div and
> inside the div i have ng-include listening to a function called viewFile()
> which is described on controllerA. on the first initial attempt i load a
> view called login.html and display it. when users logs in and its
> successful, which are handled in controllerB, i return a token and now i
> want to load main.html page using viewFile() in controllerA. is there a
> call back function or notify controller or something for this? or can i
> write a service that takes care of this for me?
>
> I'm not using ngRoute because i dont want my URL to change to
> mysite.com/#/login.html and then mysite.com/#/main.html
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.