我的任务是在选择或上传文件后我们选择或上传文件上传按钮的警告框中提醒路径名称,警告框应提醒路径名称。
这是我的HTML页面index.html
<!DOCTYPE html>
<head>
<script src="http://code.angularjs.org/1.2.9/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="ProductCtrl">
<input type="file" id="file" name="file">
<button ng-click="add()">Add</button>
<p>{{data}}</p>
</div>
<script>
var myApp = angular.module('myApp',[]);
function ProductCtrl($scope) {
$scope.data = 'none';
$scope.add = function(){
alert(file);
var f = document.getElementById('file').files[0],
r = new FileReader();
r.onloadend = function(e){
$scope.data = e.target.result;
}
r.readAsBinaryString(f);
}
}
</script>
</body>
</html>
答案 0 :(得分:0)
Hey Anil我已经对此进行了检查
var myApp = angular.module('myApp',[]);
function ProductCtrl($scope) {
$scope.data = 'none';
$scope.add = function(){
var f = document.getElementById('file').files[0],
r = new FileReader();
r.onloadend = function(e){
$scope.data = e.target.result;
alert(JSON.stringify(f));
}
r.readAsBinaryString(f);
}
}