javascript - Creating a filter in the view using AngularFire/Firebase query -


i building app in user inputs tastings, , tastings displayed in few places - on user's personal tastings page, , on "latest tastings" style page.

on tastings page, when button clicked, "basictastings()" function called, , that's want query db , view update tastings have "type: basic" (thee type: advanced).

in function, test console log outputting key() basic/advanced. i'm lost in pushing object scope objects go through ng-repeat.

finally - make sense me doing way? approaching in manner instead of through, say, jquery .click() filtering idea because thought better approach if end large amounts of data in db.

my data set as:

{   "tastings" : {     "-jlucgqblssteob7weqi" : {       "brewdate" : "2015-03-28t07:07:04.880z",       "origin" : "panama",       "overallrating" : 4.5,       "roaster" : "verve",       "roastname" : "los lajones honey",       "subdate" : 1427526458869,       "thoughts" : "cup characteristics: honey-process coffee los lajones abdundantly juicy , filled lovely stone fruit notes bing cherry , apricot. body tempered ganache.",       "type" : "basic",       "user" : "simplelogin:19"     }   },     "simplelogin:19" : {       "date" : 1427086513603,       "email" : "test@test.com",       "reguser" : "simplelogin:19",       "username" : "tester"     }   } } 

my controller listing tastings is:

myapp.controller('tastingslistcontroller',   function($scope, $firebasearray, $rootscope, $location, authentication, firebase_url) {      $scope.$emit('callforauth'); // emitter initiate $onauth function in authentication service       var ref = new firebase(firebase_url + '/tastings');      var tastingsinfo = $firebasearray(ref);      $scope.filterbasic = function() {          ref.orderbychild("type").on("child_added", function(tasting) {             console.log(tasting.key() + ' ' + tasting.val().type + ' tasting.');             if(tasting.val().type === "basic") {                 tastingsinfo.push(tasting);                 console.log(tastingsinfo);             }     });     };   }); 

and relevant ng-repeat , button trigger function:

                <md-button class="md-raised md-accent" ng-click="filterbasic()" flex>                     basic                 </md-button>             </div>         </md-toolbar>         <md-content class="md-padding">             <div class="basiccontainer" ng-repeat="tasting in tastings | orderby: 'brewdate'"> 

edit: data i'm getting in console.log occurs after each tasting "basic", should happening, contains entire array of objects, when want contain object only, , want put object array can iterate on ng-repeat.

edit 2: think i'm approaching whole thing wrong:

i've been reading , re-reading, , think see approach is, basically, firebase docs saying not do:

  • regarding data structure , filtering user own tastings: currently, i'm not indexing meaning that, data changes, have iterate through see owns what.
  • what should doing in case to, when user submits tasting, have user index within tasting, if it's going ever have 1 creator, also have tasting's key indexed user, e.g.:

tasting:

"tastings" : {     "-jlucgqblssteob7weqi" : {       "brewdate" : "2015-03-28t07:07:04.880z",       "origin" : "panama",       "overallrating" : 4.5,       "roaster" : "verve",       "roastname" : "los lajones honey",       "subdate" : 1427526458869,       "thoughts" : "cup characteristics: honey-process coffee los lajones abdundantly juicy , filled lovely stone fruit notes bing cherry , apricot. body tempered ganache.",       "type" : "basic",         "user" : {            "simplelogin:18": true,         },     }, 

user:

    "users" : {         "simplelogin:18" : {           "date" : 1427062799596,           "email" : "test@test.com",           "reguser" : "simplelogin:18",           "username" : "tester",             "tastings" : {                "-jlucgqblssteob7weqi": true,                "<tasting 2 key>": true,                ...              },                   }, 

this setup allow me set two-way relationship between tasting , creator. can through same submit function when user presses "submit" button - send data tasting, use tasting's key on user's tastings index.

  • regarding user of controller vs service: i'm doing right trying in controller.
  • what should doing to, controller, call "listingsfilter" service (or whatever decide call it) when function within controller called via button press. service should doing actual work of querying firebase listings, putting them array of kind, , sending out controller, feeds data $scope through ng-repeat iterate.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -