Well, if interest anyone, I solve it changing the UserContent factory (*which 
I didn't want to*)

angular.module('itaas').factory('UserContent', ['$injector', 'user', 
function ($injector, user) {
    var get = function () {
        if (user.isAuthenticated())
            return $injector.get('UserContentApi');


        return $injector.get('UserContentFake');
    };


    return {
        get: get
    };
}])

Then, I had to change where *UserContent* is used, to start using like 
*UserContent.get().someMethod()*


On Tuesday, October 28, 2014 1:20:43 PM UTC-2, Joberto Diniz wrote:
>
> Ok, I've found the following: 
> http://phonegap-tips.com/articles/conditional-dependency-injection-with-angularjs.html
> So I've created the following:
>
> angular.module('itaas').factory('UserContent', ['$injector', 'user', 
> function ($injector, user) {
>     if (user.isAuthenticated)
>         return $injector.get('UserContentApi');
>     return $injector.get('UserContentFake');
> }])
>
> One factory for when user is logged in, one factory for when user is not 
> logged in, so I don't have to add a lot of *if* statements throughout the 
> code.
> That works, however, when user authenticates, I'd want to *change the 
> factory instance* to be *UserContentApi* instead of *UserContentFake*.
>
> Is this possible?
>

-- 
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.

Reply via email to