Conditional “multiple” attribute in <input type=“file”> with AngularJS

前端 未结 8 2164
感情败类
感情败类 2021-01-11 18:02

I need an upload form field that may or may not allow the user to select more than one file.

I know I can do something like:



        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-11 18:39

    Solution is pretty simple since you are using directive or component - just manipulate DOM on the right moment. Take a glance here:

    app.component('myComponent', {
        templateUrl: 'tmpl.html',
        bindings: {
            str: '@'
        },
        controller: function ($element) {
            this.$postLink = function () {
                $element.find('input').attr('multiple', 'multiple');
            }
        }
    }
    

提交回复
热议问题