我试着了解AngularFire的工作原理。我正在尝试将名字和姓氏保存到我的firebase数据库中。我成功创建了“名字”输入并将其保存在Firebase中。我现在尝试添加姓氏输入,但我无法弄清楚如何使其工作。以下是我现在要做的事情:
HTML
<section ng-controller="premiercontrolleur">
<ul>
<li ng-repeat="client in clients">
<input ng-model="client.prenom" ng-change="clients.$save(client)" />
<input ng-model="client.nom" ng-change="clients.$save(client)" />
<button ng-click="clients.$remove(client)">X</button>
</li>
</ul>
<form ng-submit="addClient(newClientText)">
<input type="text" placeholder="Prénom" ng-model="newClientText.prenom" />
<input type="text" placeholder="Nom de famille" ng-model="newClientText.nom" />
<button type="submit">Ajouter le client</button>
</form>
</section>
的Javascript
var app = angular.module("crmfirebase", ["firebase"]);
app.controller("premiercontrolleur", function($scope, $firebase) {
var ref = new Firebase("https://mydirebaseurl.firebaseio.com/clients");
var sync = $firebase(ref);
$scope.clients = sync.$asArray();
$scope.addClient = function(prenom) {
$scope.clients.$add({prenom: prenom, nom: nom});
}
});
我在提交时遇到了这个错误:
Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('submit') does not support selection.
答案 0 :(得分:1)
你没有很好地匹配这些值,请记住,prenon是一个具有prenon和nom属性的对象,所以请尝试:
$scope.addClient = function(prenom) {
$scope.clients.$add({prenom: prenom.prenom, nom: prenom.nom});
}