Simple angular question driving me nuts

Associate
Joined
10 Jan 2006
Posts
483
I have a simple problem but cant seem to work out how to do it. Basically when a user clicks on a photo i want them to be able to select that photo. I have got the object back but I am not sure how to access it in the view without having to push to an array an ng repeat over it which cant be the best way to do it.

At the moment photo.flickr gives me the object back but I cant work out how to save to self.photo and then access the value in the view

Code:
function FlickrController($http){
  var self = this 
  self.photo = null
  self.all = []
  self.images = []

 self.showPhoto = function(photo){
    self.photo = photo.flickr
    console.log(self.photo)
   }
 }
 
The controller should have $scope as a parameter and then assign the photo to the $scope.

The $scope is then available in your view.
 
Should be pretty straightforward as trucamo suggests. Or if you're using controllerAs syntax, just do 'yourcontroller.photo'. What does your view look like?
 
Code:
<div ng-app='flickrApp' ng-controller='FlickrController as flickr'>

{{flickr.photo}}
</div>

I am using the constroller as syntax but when I do this it does not show up?
 
What data type are you expecting the photo property to be? is it an object? If so try accessing one of it's properties in the curly braces, e.g. {{ flickr.photo.id }} or try {{ JSON.parse(flickr.photo) }}

EDIT: just seen your previous comment, ignore :)
 
Back
Top Bottom