meanstacky
meanstacky

Reputation: 397

Unable to display $scope in view

I am querying a database and retrieving all the images belonging to the logged-in user, here is that code in uploadController:

UserImage.get($scope.user_id)
   .success(function(data) {

       $scope.userArray = data;

       $location.path('/display');
    });

I can console log the value of data and it is (first document):

0: Object
__v: 0
_id: "563bd07c7a49a7ac9ae1c513"
date: "2015-11-05T21:56:12.312Z"
gallery: "first gallery"
name: "1b0f6d56-9ed6-4412-a0d6-897a25fb3a84-460x360.jpeg"
user: "563bd0527a49a7ac9ae1c512" 

so now I test that the target view (display.html) can receive the $scope.data:

<<div>{{userArray[0].name}}</div>

The $scope.userArray is not available to the display.html. I tested the $scope in plunker and it worked ok: http://plnkr.co/edit/q5XXnfl3JxkRdG0jLyps?p=preview So I am a bit stumped.

Upvotes: 0

Views: 105

Answers (1)

t0mpl
t0mpl

Reputation: 5025

first of all you should use ".then" instead of ".success" to use to promise system. If you want to know more about it

And i think your problem is also connected with $location.path('/display'); you ask your application to change location as soon as you get the answer, so it is probably loading another controller and stopping with your current one.

Upvotes: 1

Related Questions