4 javascript jquery openfiledialog input-type-file angularjs
我正在创建一个网络应用程序,其中有一个输入字段
<input type="file" ng-model="getfilename" />
和一个按钮
<button ng-click="clickfordetails()">Click Here!</button>
以及<P>{{file}}</p>
当用户从输入字段输入文件后单击按钮时的段落标记,他应该在其中获取文件名{{file}}
这是我的控制器
$scope.clickfordetails=function() {
$scope.file=$scope.getfilename;
}
Run Code Online (Sandbox Code Playgroud)
但是当我将控制器编辑为此时,我无法获取文件名
$scope.clickfordetails=function() {
console.log($scope.getfilename);
}
Run Code Online (Sandbox Code Playgroud)
我的控制台(谷歌浏览器)中的值是 Undefined
我需要怎么做??
使用以下指令
directive('customFileInput', [function () {
return {
link: function (scope, element, attrs) {
element.on('change', function (evt) {
var files = evt.target.files;
scope.filename=files[0].name
});
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2684 次 |
| 最近记录: |