Я новичок в Angular, и я пытаюсь осуществить загрузку логотипа с использованием Angular 1. После выбора файла, если я нажму, загрузить его показ как неопределенный. Пожалуйста, помогите.
Вот мой HTML-код:
<input type="file" data-file-model="organisationCtrl.filesArray" >
<button type="submit" data-ng-click="organisationCtrl.uploadFile()">save</button>
Вот угловая часть:
// главный контроллер:
(function() {
'use strict';
angular.module('vyahara').controller('OrganisationCtrl', OrganisationCtrl);
// The $inject property is an array of service names to inject.
OrganisationCtrl.$inject = [ '$http', '$window', '$location', '$rootScope',
'GenericPostService' ];
function OrganisationCtrl($http, $window, $location, $rootScope,
GenericPostService) {
var organisationCtrl = this;
// Проверка имени пользователя (для понимания), которая работает нормально:
organisationCtrl.validUser = validUser;
function validUser()
{
console.log("sdagfsdfgsdfgsdfgsdfgsdfg");
if (organisationCtrl.userName != null
&& organisationCtrl.userName != "") {
if (organisationCtrl.userName.length < 8) {
swal('', 'User Id must have 8-15 Chracters', 'warning');
organisationCtrl.userName = "";
}
var userCreationBean = {
"userCreationBean" : {
userNumber : organisationCtrl.userName,
}
}
GenericPostService
.post('/user/valid/search', userCreationBean)
.then(
function(response) {
if (response.statusCode == 200) {
swal('', 'User Name Already Taken',
'warning');
organisationCtrl.userName = "";
} else {
organisationCtrl.userName = organisationCtrl.userName;
}
});
}
}
// загрузка файла не работает
organisationCtrl.uploadFile = uploadFile;
function uploadFile() {
var fileUpload = new FormData();
console.log("You are In!!!!",organisationCtrl.filesArray);
fileUpload.append("fileUpload", organisationCtrl.filesArray);
console.log(">>>>>>>>>>",fileUpload);
GenericPostService.postWithConfig('/organization/createFile', fileUpload, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.then(
function(response) {
if (response.statusCode == 200) {
swal('', 'File Upload Successful');
});