我正在使用控制器作为语法.
当我的文件输入改变时,我想触发一个功能.
怎么做?
下面是我的代码与$ scope语法
<input class="upload" type="file" accept="image/*" ng-model="image"
onchange="angular.element(this).scope().uploadImage(this)">
Run Code Online (Sandbox Code Playgroud)
如此处所示,您可以使用自定义指令来侦听输入文件中的更改.
view.html:
<input type="file" custom-on-change="uploadFile">
Run Code Online (Sandbox Code Playgroud)
controller.js:
app.controller('myCtrl', function($scope){
$scope.uploadFile = function(event){
var files = event.target.files;
};
});
Run Code Online (Sandbox Code Playgroud)
directive.js:
app.directive('customOnChange', function() {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var onChangeHandler = scope.$eval(attrs.customOnChange);
element.bind('change', onChangeHandler);
}
};
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18945 次 |
| 最近记录: |