我有一个使用AngularJs的动态添加/删除字段,我想将该数据发送到我的Firebase数据库。我不知道我怎么能这样做或者是否有可能。如果不是,有人可以告诉我如何将数据从$scope
发送到var阵列或给我一个替代方案?
以下是一些代码:
<td><input type="text" ng-model="choice.Locatie" name="Locatie" placeholder="Locatie" ></td>
<td><input type="text" ng-model="choice.Nr" name="Nr" placeholder="Nr" style="width: 40px;"></td>
<td><input type="text" ng-model="choice.Greutate" name="Greutate" placeholder="Greutate"></td>
<td><input type="text" ng-model="choice.Referinta" name="Referinta" placeholder="Referinta"></td>
<td><input type="text" ng-model="choice.Observatii" name="Observatii" placeholder="Observatii"></td>
这是动态添加/删除字段的脚本:
var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {
$scope.choices = [{id: 'pas1'}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length+1;
$scope.choices.push({'id':'pas'+newItemNo});
};
$scope.removeChoice = function() {
var lastItem = $scope.choices.length-1;
$scope.choices.splice(lastItem);
};
});
火力地堡:
<script src="https://www.gstatic.com/firebasejs/3.6.5/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "api-key",
authDomain: "example.firebaseapp.com",
databaseURL: "https://example.firebaseio.com",
storageBucket: "example.appspot.com",
messagingSenderId: "0000000000"
};
firebase.initializeApp(config);
</script>