2
我有一个指令,将一个文件上传输入域放在DOM上,然后我希望能够在该文件更改时调用函数。我怎样才能让更改函数在不放置在编译器区域的情况下工作?我知道它不属于那里,因为我被告知编译器的内存密集程度更高,只能用于预渲染的东西。Angular自定义指令调用输入域更改的函数
angular.module('myApp').directive('customDirective', ['$http', function ($http) {
return {
controller() {
},
compile(element) {
const $fileinput = $('<input type="file" accept=".csv">').appendTo(element);
return {
controller:() => {
$fileinput.on('change', (e) => {
// Stuff happens
});
},
link:() => {
},
};
},
};
}]);
我想你只能使用带有NG-模型NG-变化? ng-model不能使用文件:/ https://docs.angularjs.org/api/ng/directive/ngChange –
@ToriHuang我编辑了我原来的文章。这应该适用于你需要的东西 –
这是非常棒的细节,谢谢! –