angular实现changeFile上传[方法一]

angular实现changeFile上传[方法一]

1
2
3
4
<div ng-controller="MyCtrl">
<input type="file" onchange="MyCtrl.prototype.setFile(this)">
{{theFile.name}}
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
var myApp = angular.module('myApp',[]);
function MyCtrl($scope, $window) {
$scope.name = 'Superhero';
MyCtrl.prototype.$scope = $scope;
}
MyCtrl.prototype.setFile = function(element) {
var $scope = this.$scope;
$scope.$apply(function() {
$scope.theFile = element.files[0];
});
};