我使用Ionic和AngularFire制作我的应用程序,但我有问题:
我的请求没有记录在数据库中,当我单击提交按钮时,控制台会调用以下错误:TypeError:无法读取未定义的属性"push"。我不知道该怎么办。。。请帮帮我。如有任何进一步的消息,我随时恭候。
这是我的html代码:
<form ng-submit="AddEvent()">
<label class="item item-input item-stacked-label">
<span class="input-label"><i class="fa fa-pencil"></i> Nom de l'événement</span>
<input type="text" ng-model="events.nameid">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label"><i class="icon ion-ios-information"></i> Description</span>
<br><textarea ng-model="events.descriptionid"></textarea>
</label>
<label class="item item-input item-stacked-label">
<span class="input-label"><i class="fa fa-location-arrow"></i> Adresse</span>
<input type="text" ng-model="events.addressid">
</label>
<button class="button" type="submit" id="success-btn-create"><i class="fa fa-arrow-right"></i></button></form>
我的控制器JS:
myApp.controller('Step1Ctrl', ['$scope', 'Events', 'Auth', '$rootScope', '$state', function($scope, $Events, Auth, $rootScope, $state) {
$scope.events = Events;
var Events = {fbRef: "https://myApp.firebaseio.com/Events"};
$scope.AddEvent = function() {
var eventsRef = eventsRef.push();
$scope.events.push({
"nameid": nameid,
"descriptionid": descriptionid,
"addressid": addressid,
});
}
$scope.auth = Auth;
// any time auth status updates, add the user data to scope
$scope.auth.$onAuth(function(authData) {
$scope.authData = authData;
});
$scope.create = function() {
$state.go('tabstep1');
};
$scope.close = function() {
$state.go('tabdash');
};
}])
我的服务JS:
angular.module('starter.services', ['ngCordova','firebase'])
myApp.factory("Events", ["$firebaseArray", function($firebaseArray) {
var eventsRef = new Firebase("https://myApp.firebaseio.com/Events");
return $firebaseArray(eventsRef);
}]);
调用eventsRef.push()
时,变量eventsRef
未定义。此外,您在push()
调用中没有执行任何操作。
尝试:
var eventsRef = [];
eventsRef.push(somethingToAddToEventsRef);