2017-09-13 15 views
0

firebaseデータベースに4つの値を挿入しようとしています(Equipment、Type、停止時間の開始と停止時間の終了)。停止時間の値の開始と終了はdatetime-localにあります。値を挿入しようとすると、最初の2つの値のノードが機器とタイプになります。なぜ私はdatetime-local値を挿入しないのか分かりません。日時ローカルfirebaseデータベースで動作していません

MY HTML

<div class="row"> 
    <div class="col-xs-12"> 

    <div class="form-group col-xs-6 col-xs-offset-3" id="equipList"> 
     <label for="selectequ">Select Equipment</label> 
     <select class="form-control" id="selectequ" data-ng-model="equipment" 
      > 
     <option data-ng-repeat="eq in allEquipments" >{{eq}}</option> 
     </select> 

     {{equipment}} 
    </div> 

     <div class="form-group col-xs-6 col-sm-6 col-md-6 col-lg-6 col-xs-offset-3" id="Type"> 
     <label for="searchType">Search by Type:</label> 
     <select class="form-control" id="searchType" data-ng-model="type"> 
      <option value="" disabled="" selected="" style="display: none">Select type of maintenance</option> 
      <option>Corrective Maintenance</option> 
      <option>Preventive Maintenance</option> 
      <option>Standby</option> 
     </select> 
     </div> 

     {{type}} 

    </div> 
</div> 

<div class="row"> 

    <div class="form-group col-xs-6 col-xs-offset-3"> 
     <label for="date">Start of Downtime</label> 
     <input type="datetime-local" class="form-control" placeholder="Day, Month, Year" data-ng-model="startDT"/> 
    </div> 
     {{startDT}} 
    <div class="form-group col-xs-6 col-xs-offset-3"> 
     <label for="date">End of Downtime</label> 
     <input type="datetime-local" class="form-control" placeholder="Day, Month, Year" data-ng-model="endDT"/> 
    </div> 

    {{endDT}} 

    </div> 

<div class="row"> 
     <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" id="central"> 
      <a class="btn cd-add-to-cart cd-add-to-cart:hover cd-add-to-cart:active" role="button" data-ng-click="manageDowntime()">MANAGE <span class="glyphicon glyphicon-tasks"></span></a> 
     </div> 
    </div> 

MY ANGULARJS

/*global angular*/ 
var app = angular.module('downtime', ['ngRoute', 'firebase']); 

app.config(['$routeProvider', function ($routeProvider) { 
    'use strict'; 
    $routeProvider.when('/downtime', { 
     templateUrl: 'downtime/downtime.html', 
     controller: 'downtimeCtrl' 
    }); 
}]); 

app.controller('downtimeCtrl', ['$scope', '$firebaseObject', '$firebaseArray', function ($scope, $firebaseObject, $firebaseArray) { 
    'use strict'; 

    $scope.allEquipments = []; 
    $scope.allSystems = []; 

    $scope.manageDowntime = function() { 
     var doesExist = false; 
     angular.forEach ($scope.data , function (d) { 
     angular.forEach (d.equipments, function (e) { 
     }) 
    }); 
     firebase.database().ref('downtime/' + $scope.equipment + '/downtime').child($scope.equipment).set({ 
      equipment: $scope.equipment, 
      type : $scope.type, 
      start: $scope.startDT, 
      end: $scope.endDT 
     }); 
}; 

    var ref = firebase.database().ref(); 
     var data = ref.child("data"); 
     var list = $firebaseArray(data); 

     list.$loaded().then(function(data) { 
      $scope.data = data; 
      angular.forEach ($scope.data , function (d) { 

       $scope.allSystems.push(d.$id); 

       angular.forEach (d.equipments, function (e) { 
        $scope.allEquipments.push(e.equipment); 
        console.log($scope.allEquipments); 
       }) 
      }); 
      console.log($scope.data); 
     }).catch(function(error) { 
      $scope.error = error; 
     }); 


}]); 

enter image description here

答えて

1

私はfirebaseがデータ型として日付を受け入れていない願っています。したがって、それらを文字列として変換し、datetimeローカル値として格納します。 See this documentation for datatypes accepted in set method

object, array, string, number, boolean, or null // these are the datatypes which firebase will accept. 

ステップ1:

store them as datetime-local values in firebase, while retrieving the data, push the date object. 

var start_end=new Date(start); 
//you will get date object, you can append this to input type date if you wish. 
関連する問題