How to use input type file in angular material

后端 未结 4 1283
萌比男神i
萌比男神i 2021-02-01 02:50

How to use input type file in angular material

Hi, I am using angular material for designing. when i go on angular material site there no input type fil

4条回答
  •  自闭症患者
    2021-02-01 03:27

    Here is a workaround if all you want is a nicely displayed file input button.

    Html

    
    
    

    Component

    onFileSelected() {
      const inputNode: any = document.querySelector('#file');
    
      if (typeof (FileReader) !== 'undefined') {
        const reader = new FileReader();
    
        reader.onload = (e: any) => {
          this.srcResult = e.target.result;
        };
    
        reader.readAsArrayBuffer(inputNode.files[0]);
      }
    }
    

    Inspired by this Angular Material Github Issue comment https://github.com/angular/material2/issues/3262#issuecomment-309000588

提交回复
热议问题