selectedMeals.js 722 B

123456789101112131415161718192021222324
  1. app.directive('selectedMeals',['$interval',function($interval){
  2. return {
  3. replace: true,
  4. resctrict: 'E',
  5. templateUrl: 'app/views/selected-meals.html',
  6. scope: {
  7. meals: '=',
  8. },
  9. controller: function($scope){
  10. $interval(function(){
  11. if(firebase.auth().currentUser){
  12. $scope.ref = firebase.database().ref().child('users').child(firebase.auth().currentUser.uid).child('meals');
  13. }
  14. },1000)
  15. $scope.unselect = function(i){
  16. if(firebase.auth().currentUser){
  17. var keys = Object.keys($scope.meals);
  18. $scope.meals[keys[i]].isSelected = false;
  19. $scope.ref.child(keys[i]).set($scope.meals[keys[i]]);
  20. }
  21. }
  22. }
  23. }
  24. }])