对于自我编程和学习的全新,我请求社区帮助我们。
我有一个表单数据和控制器,可以捕获表单数据。我正在使用add方法将图像和数据推送到firebase。我无法推送数据和图像,但是当我只发送图像时,它会被发送到firebase。请参阅HTML表单,服务和控制器代码。
Services.js:
.factory('newStory', function($firebaseArray) {
var messagesRef = new Firebase("https://mydepressionproject-
6c480.firebaseio.com/");
return $firebaseArray(messagesRef);
})
Controller.js
.controller('sharetheOpinionCtrl', function($scope,newStory, $cordovaCamera ,$ionicHistory) {
var myblog=newStory;
$ionicHistory.clearHistory();
$scope.upload = function() {
var options = {
quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: false
};
var name=$scope.name;
var title=$scope.title;
var post=$scope.post
$cordovaCamera.getPicture(options).then(function(imageData) {
var dataNew={
image:imageData,
name:name,
post:post};
myblog.$add({dataNew}).then(function() {
alert("Image has been uploaded");
});
}, function(error) {
console.error(error);
})
}
})
camera.html:
<ion-view title="My Images">
<ion-nav-buttons side="right">
<button class="button button-icon icon ion-camera" ng-click="upload()">
</button>
</ion-nav-buttons>
<ion-content>
<div class="container">
<form role="form" name="form" id="contact-form" class="form-horizontal" novalidate>
<div class="form-group">
<label for="FirstName">First name:</label>
<input type="text" class="form-control" name="FirstName" id="FirstName" placeholder="enter first name" ng-model="name" required>
</div>
<div class="form-group">
<label for="Title">Title Of The Blog:</label>
<input type="text" class="form-control" name="title" id="title" placeholder="enter title name" ng-model="title" required>
</div>
<div class="form-group">
<label for="Title"> Tell Your Story:</label>
<textarea class="form-control" name="post" id="post" placeholder="write your story" ng-model="post" required></textarea>
</div>
</form>
</div>
</ion-content>
</ion-view>