AngularJs: How to check for changes in file input fields?

前端 未结 15 1158
傲寒
傲寒 2020-11-22 09:06

I am new to angular. I am trying to read the uploaded file path from HTML \'file\' field whenever a \'change\' happens on this field. If i use \'onChange\' it works but when

15条回答
  •  盖世英雄少女心
    2020-11-22 09:27

    The simplest Angular jqLite version.

    JS:

    .directive('cOnChange', function() {
        'use strict';
    
        return {
            restrict: "A",
            scope : {
                cOnChange: '&'
            },
            link: function (scope, element) {
                element.on('change', function () {
                    scope.cOnChange();
            });
            }
        };
    });
    

    HTML:

    
    

提交回复
热议问题