Ionic Angular Firebase pass value problem

Hi I’m new on Ionic, and I have been a couple of days with this problem.
I create an app from chat examples, and I want to connect and read to my firebase database.
The first part is woking.- I can retreive and show data from firebase, but my problem is when I click on the “Item list” and want to show full description, I don not understand how to pass value and get the data again.

Here are my scripst:
app.js ( I’m only showing part of them )

    angular.module('starter', ['ionic', 'starter.controllers', 'starter.services','firebase'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleLightContent();
    }
  });
})


.config(function($stateProvider, $urlRouterProvider) {

  // Ionic uses AngularUI Router which uses the concept of states
  // Learn more here: https://github.com/angular-ui/ui-router
  // Set up the various states which the app can be in.
  // Each state's controller can be found in controllers.js
  $stateProvider

  // setup an abstract state for the tabs directive
    .state('tab', {
    url: "/tab",
    abstract: true,
    templateUrl: "templates/tabs.html"
  })

  // Each tab has its own nav history stack:

  .state('tab.dash', {
    url: '/dash',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl'
      }
    }
  })

  .state('tab.chats', {
      url: '/chats',
      views: {
        'tab-chats': {
          templateUrl: 'templates/tab-chats.html',
          controller: 'ChatsCtrl'
        }
      }
    })
    .state('tab.chat-detail', {
      url: '/chats/:chatId',
      views: {
        'tab-chats': {
          templateUrl: 'templates/chat-detail.html',
          controller: 'ChatDetailCtrl'
        }
      }
    })

  .state('tab.account', {
    url: '/account',
    views: {
      'tab-account': {
        templateUrl: 'templates/tab-account.html',
        controller: 'AccountCtrl'
      }
    }
  });
  
 

  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/tab/dash');

});

Here is my services file — services.js

    angular.module('starter.services', [])

.factory('fireBaseData', function($firebase) {
  // Might use a resource here that returns a JSON array
	var ref = new Firebase("https://scorching-fire-921.firebaseio.com/")
	refCorales = new Firebase("https://scorching-fire-921.firebaseio.com/corales/");
	
 var fireBaseData = {
	all: refCorales,    
		get: function (chatId) {
		return $firebase(ref.child('refCorales').child(chatId)).$asObject();
		}
	}; 
  return {
        ref: function() {
            return ref;
        },
         refCorales: function() {
            return refCorales;
        }
    }
});

And the controller file – controller.js

    angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope) {})

.controller('ChatsCtrl', function($scope, $firebase, fireBaseData) {
     $scope.corales  = $firebase(refCorales);
 
})

.controller('ChatDetailCtrl', function($scope, $stateParams, fireBaseData) {
	
  $scope.corales = refCorales.get($stateParams.chat$id);
})



.controller('AccountCtrl', function($scope) {
  $scope.settings = {
    enableFriends: true
  };
});

Any idea will be we received , thank you,

Victor

So what does a single object look like? At first glance, this could be the problem, $stateParams.chat$id

It should be $stateParams.chatId like you have defined in your states and services.

Hi : Mike :

Thank you for your response, and you’re right, the problem was that, I was using: $stateParams.chat$id instead of $stateParams.chatid, and Also I found an error the “get” function, I aready fixed and the app it’s running Ok.
It retrive the data from Firebase !

Regards,

Victor

1 Like

Hi caribesoft, could you share the solution for the get ?