Ad

Angularjs - Query Parse.com $stateParams

I’m looking for support on a query using $stateParams in Angularjs. The query is returning undefined.

I have an array of photos in a news feed. Clicking on a photo should take you to a new page of that photo. I'm below attempting to just spit out the photo id in Network google dev tools tab first.

environment: angularjs, javascript parse api using promises/factory/controller/view

Route

.state(‘gallery.item', {
      url: '/item/:galleryid',
      views: {
        menuContent: {
          controller: 'ItemController as vm',
          templateUrl: path + ‘/galleryitem/item.html'
        }
      }
    })

Factory - Parse query

function getFirst(Class, term1, term2){

        var defer = $q.defer();
        var ParseString = Parse.Object.extend(Class);
        var query = new Parse.Query(ParseString);
         query.equalTo(term1, term2);
         if(Class==='Gallery') {
            query.equalTo('approve', true);
            query.ascending('createdAt');
         }
        query
        .first()
        .then(function(resp){
          console.log('getFirst', resp);
          if (resp === undefined) {
            defer.reject(resp);
          } else {
            defer.resolve(resp);
          }

        });

    return defer.promise;
  }

return {
getFirst: getFirst
}

ItemController

function ItemController($scope, $state, $rootScope, $stateParams, Factory) {
var vm = this;

getItemDetails();

function getItemDetails() {

vm.Gallery = [];

Factory
.getFirst('Gallery', 'objectId', $stateParams.id)
.then(function(resp) {

vm.GalleryData = response;

 console.log(resp);

 vm.Gallery.push({
            id: resp.id,
        });

      });

Any help would be greatly appreciated.

Thanks

Cameron

Ad

Answer

In your routing config you use url: '/item/:galleryid', but in controller you are looking for $stateParams.id which doesn't match routing config

Change to $stateParams.galleryid

Ad
source: stackoverflow.com
Ad