在 ng-submit 表单中上传图片
Upload image within ng-submit form
我是 Angular.js 的新手,我想知道如何在我的 ng-submit 表单中上传图片。它非常适合基于下一个字段,但对于文件,它只给我 'choose file' 按钮,而在点击提交按钮后不显示它。
<form ng-submit="addartikel()">
<input type="text" placeholder="Bezeichnung" ng-model="newartikel.name" />
<input type="text" placeholder="Kategorie" ng-model="newartikel.kategorie" />
<input type="text" placeholder="Preis" ng-model="newartikel.preis" />
<input type="file" placeholder="Bild" ng-model="newartikel.thumb" />
<input type="submit" value="Artikel hinzufügen" />
至于控制器:
webShop.controller('InventarController', ['$scope', '$http', function($scope, $http){
$scope.addartikel = function(){
$scope.inventar.push({
name: $scope.newartikel.name,
kategorie: $scope.newartikel.kategorie,
preis: parseInt($scope.newartikel.preis),
thumb: $scope.newartikel.thumb,
available: true
});
非常感谢您的帮助:)
使用 Angular 文件 Upload.It 在 https://github.com/nervgh/angular-file-upload
中可用
我是 Angular.js 的新手,我想知道如何在我的 ng-submit 表单中上传图片。它非常适合基于下一个字段,但对于文件,它只给我 'choose file' 按钮,而在点击提交按钮后不显示它。
<form ng-submit="addartikel()">
<input type="text" placeholder="Bezeichnung" ng-model="newartikel.name" />
<input type="text" placeholder="Kategorie" ng-model="newartikel.kategorie" />
<input type="text" placeholder="Preis" ng-model="newartikel.preis" />
<input type="file" placeholder="Bild" ng-model="newartikel.thumb" />
<input type="submit" value="Artikel hinzufügen" />
至于控制器:
webShop.controller('InventarController', ['$scope', '$http', function($scope, $http){
$scope.addartikel = function(){
$scope.inventar.push({
name: $scope.newartikel.name,
kategorie: $scope.newartikel.kategorie,
preis: parseInt($scope.newartikel.preis),
thumb: $scope.newartikel.thumb,
available: true
});
非常感谢您的帮助:)
使用 Angular 文件 Upload.It 在 https://github.com/nervgh/angular-file-upload
中可用