0

What is stopping my view from being rendered after my "User" service is updated with the information necessary to view?

Pseudocode:

  1. User signs in and the profile.uid information should be set. The profile.uid is later used as a child in my Firebase path.
    .factory('User', function (FirebaseUrl, $firebaseArray) {
        var o = {};

        o.setUser = function(authData) {
             o.profile.uid = authData.uid;
        }
        o.getProfile = function() {
            return o.profile;
        }
        return o;
    }
  1. Using $state.go('view') with Angular UI-Router I go to the following view:

Controller:

.controller('viewCtrl', function ($scope, User, $firebaseArray, FirebaseUrl) {

    var profile = User.getProfile();

    //if I hardcore "facebook:213032130516" in the .child(), everything renders correctly...

    var messagesRef = new Firebase(FirebaseUrl + 'user_meta/').child(profile.uid);
    var query = messagesRef.orderByChild("timestamp").limitToLast(5);

    $scope.list = $firebaseArray(query);
}

HTML:

<div ng-repeat="dog in list">
     <h2> {{dog.key}}</h2>
</div>

As it stands currently, the view doesn't render. No errors are logged, just the view is blank. As per the comment in the controller code, when I hardcode the .child(profile.uid), so it becomes .child('facebook:112351), the view renders correctly.

Can someone help me with a better solution to implement, and ultimately, why this is not working?

Thanks!

3
  • Nothing here calls setUser(), so getProfile() can't work. There are also various other syntax errors in the code. Instead of providing pseudo-code, try to isolate the problem in a jsfiddle/jsbin and then provide an MCVE based on that here. That was we get the complete (but minimal) code and we can look at the jsfiddle/jsbin to see it in action. The easier you make it for us to help, the more likely you are to get useful help. Commented Apr 30, 2016 at 3:41
  • Thanks Frank. I will do as soon as possible. Aka tomorrow when I can get to my computer. Thanks guys. Commented Apr 30, 2016 at 4:12
  • Frank, I couldn't replicate the behavior when making the MCVE. Instead, I found this was resolved when I cold started my entire application from command line, that the code works as it should (ie. >ionic serve). However if I call the function without restarting, or while I'm working on my code it doesn't operate correctly. For the time being I'm assuming it's a small bug in the production environment that will be difficult to reproduce in the mobile environment. Commented May 5, 2016 at 0:34

2 Answers 2

1

It is hard to be 100% sure by just looking at this two pieces of code, but I would assume that you don't pass the data when you call setUser somewhere else. Try to log it out and see where you lose it. Do you have a github repo of this project that we could look at?

Sign up to request clarification or add additional context in comments.

3 Comments

I will do this as soon as possible. It might take me a bit to figure it out (I'm a noob), but yeah I'll try to get you the information asap. I'm thinking it has something to do with not having an $apply or $digest loop in and the view not re-rendering
I don't think the problem is with $apply or $digest. Since it works with hard-coded data it is safe to assume that the problem is setUser function or before it.
Max, I couldn't replicate the behavior when making the MCVE. Instead, I found this was resolved when I cold started my entire application from command line, that the code works as it should (ie. >ionic serve). However if I call the function without restarting, or while I'm working on my code it doesn't operate correctly. For the time being I'm assuming it's a small bug in the production environment that will be difficult to reproduce in the mobile environment
1

you have an undefined authData in your user factory.

6 Comments

Sorry, I've edited it accordingly. authData is provided from a function inside my userFactory. Thanks for correcting.
are you initalizing profile.uid prior to this view? do you get an array at all? try to add $scope.list.$loaded(console.log) to help yourself debug.
It is being initialize, I'm just not sure if it's before the view is being rendered. Seeing that my profile information is being updated in the factory, I'm wondering if/how to apply an $apply when that occurs. Perhaps that view is already rendered behind the scene at my login screen?
Are you using ui-router? if you are it is worth mentioning resolve parameter when you define states.
No I am not @Muli Yulzary. I wanted to figure out if there's a way to do it without resolve. Is this possible? Only reason being, I would like to have an if based statement which uses parameters available in the controller; something I don't believe you can do with resolve.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.