material design - How to clear all the md-input fields at once inside a md-form using an external button in Angular 2/2+/4 -


i want clear fields inside md-form @ once using external clear button in normal html forms. problem md-form contains md-input fields instead of regular input fields. simple reset function won't trigger that.

i've set type of each field 'search' gives kind of control it's u have manually click , remove each value of filed. want erase them @ once.

is there proper way to this? in advance.

form code

<form class="formwidth" (ngsubmit)="searchclass()" #myform="ngform">       <table class="fullwidth" cellspacing="0">         <tr>           <td>           </td>           <td>             <md-input-container div="addclassname" *ngif="classclicked === true">             <input [(ngmodel)]="message.classname" mdinput placeholder="class name" id="classname" name="classname" type="search" >           </md-input-container>             <md-input-container div="addjarname" *ngif="jarfileclicked === true">               <input [(ngmodel)]="message.jarname" mdinput placeholder="jar file name" id="jarname" name="jarname" type="search" >             </md-input-container>             <md-input-container div="addversion" *ngif="versionclicked === true">               <input [(ngmodel)]="message.version" mdinput placeholder="version" id="versionnumber" name="versionnumber" type="search" >             </md-input-container>             <md-input-container div="adddirectory" *ngif="directoryclicked === true">               <input [(ngmodel)]="message.directory" mdinput placeholder="directory" id="directoryname" name="directoryname" type="search" >             </md-input-container>             <md-input-container div="adddependentclass" *ngif="dependentclicked === true">               <input [(ngmodel)]="message.dependentclass" mdinput placeholder="dependent class name" id="dependentclassname" name="dependentclassname" type="search" >             </md-input-container>           </td>       </table>       <br>       <p *ngif="classclicked === true || jarfileclicked === true || versionclicked === true || directoryclicked === true || dependentclicked === true">         <button md-raised-button color="accent" type="submit" id="submitbutton">submit</button>         <button md-raised-button id="clearbutton" (click)="setalltofalse() && clearfields()">clear</button>       </p>     </form>  

p.s : tried typescript well. don't work

clearfields(){     this.message.jarname="";     this.message.classname="";     this.message.version="";     this.message.directory="";     this.message.dependentclass="";    } 

simply calling clearfields() method inside method worked.

setalltofalse(){     this.classclicked = false;     this.jarfileclicked = false;     this.versionclicked = false;     this.directoryclicked = false;     this.dependentclicked = false;     this.condition_1 = false;     this.condition_2 = false;     this.condition_3 = false;     this.condition_4 = false;     this.condition_5 = false;     this.condition_6 = false;     this.condition_7 = false;     this.clearfields();   } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -