angularjs - Ionic Angular Firebase pass value to another tab -


i'm new on ionic, , have been couple of days problem. create app chat examples, , want connect , read firebase database. first part woking.- can retreive , show data firebase, problem when click on "item list" , want show detail description, don not understand how pass value , data again.

here scripst: app.js ( i'm showing part of them )

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services','firebase'])  .run(function($ionicplatform) {  $ionicplatform.ready(function() { // hide accessory bar default (remove show accessory bar    above keyboard // 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) {  $stateprovider  // setup abstract state tabs directive .state('tab', { url: "/tab", abstract: true, templateurl: "templates/tabs.html" })  // each tab has 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 above states matched, use fallback   $urlrouterprovider.otherwise('/tab/dash');    }); 

here services file --- services.js connect firebase

angular.module('starter.services', [])  .factory('firebasedata', function($firebase) {   // might use resource here returns 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 here 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   };  }); 

when click on item of list, i'm receiving following error message: typeerror: refcorales.get not function

any idea how avoid erro? in advance, thank !

victor

the problem see services code unclear , not returning way acces var firebasedata. why making 2 firebase references , not simple using ref.child('corales')? solution:

.factory('firebasedata', function($firebase) {   //firebase reference   var ref = new firebase("https://scorching-fire-921.firebaseio.com/")   return {     ref: function(){        return ref;     },     //i don't know if necessary     refcorales: function(){       return ref.child('corales');     },     get: function(chatid){       $firebase(ref.child('corales').child(chatid)).$asobject();     }   }; }) 

update changes controller:

.controller('chatsctrl', function($scope, firebasedata) {   $scope.corales = firebasedata.refcorales(); }) .controller('chatdetailctrl', function($scope, $stateparams, firebasedata) {   $scope.corales = firebasedata.get($stateparams.chat$id); }) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -