作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是ionic的新手,我想上传图片,因此我使用“ng-file-upload”上传我的图片。
但代码仅在我删除“ ion-content ”时才起作用。我的模板是:
<ion-view view-title="IQ Marketplace" ng-controller="SellCtrl">
<ion-content class="padding" >
<div class="list">
<form ng-submit="submitAds()" name="form" novalidate>
<label class="item item-input">
<span class="input-label">Picture</span>
<input type="file" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'"
accept="image/*" >
</label>
<input type="submit" class="button button-block button-positive" value="Save" ng-disabled="form.$invalid">
</form>
</div><!--list-->
</ion-content>
</ion-view>
.controller('SellCtrl', function($scope,Upload) {
$scope.submitAds = function() {
console.log("ayman "+ $scope.file)
$scope.upload($scope.file);
};
$scope.upload = function (file) {
Upload.upload({
url: 'http://localhost/IQM/public/ads',
data: {file: file, 'username': $scope.test}
}).then(function (resp) {
console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
}, function (resp) {
console.log('Error status: ' + resp.status);
}, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
});
};
});
TypeError: Cannot read property 'name' of undefined
at controllers.js:84
at ionic.bundle.js:23476
at Scope.$eval (ionic.bundle.js:24673)
at Scope.$digest (ionic.bundle.js:24484)
at ionic.bundle.js:24712
at completeOutstandingRequest (ionic.bundle.js:14221)
at ionic.bundle.js:14493
最佳答案
我猜你已经介绍了 Ionic Framework .
这显然是 angular 的 scope
问题。
您定义了一个 ng-model="file"
内ion-content
.虽然 ion-content
创建一个新的 scope
,因此您无法检索变量 file
直接地。
请引用doc ,它说:
Be aware that this directive gets its own child scope.
dot notations
喜欢:
// controller
$scope.data = {}
// html
<ion-content class="padding" >
...
<input ng-model="data.file" />
...
</ion-content>
$scope.data.file
得到值.
scope
概念。
关于angularjs - 为什么上传文件对 ion-content 不起作用?如果我去除 ion-content ,就可以工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33386424/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!