Get a value from mdInput

2019-09-19 03:16发布

问题:

So I have a md-input and some button.

<md-input-container >
   <input mdInput #myInput name="myInput" type="password" placeholder="Yeah">
</md-input-container>
<button md-raised-button (click)="authenticate(myInput)">Start</button>

This button sends the whole md-input. I fill in my input and that's what I'm getting when I click the button

<input _ngcontent-uqn-44="" mdinput="" name="myInput" placeholder="Yeah" type="password" ng-reflect-placeholder="Yeah" ng-reflect-type="password" class="mat-input-element" ng-reflect-id="md-input-1" id="md-input-1" aria-describedby="">

I don't see any property/attribute which contains the value I pasted in Input. So how could I get the value? Like myInput.value?

回答1:

I don't see any issue with your code, there may be something else which is causing issue.

<md-input-container >
    <input mdInput #myInput name="myInput" type="password" placeholder="Yeah">
 </md-input-container>
 {{myInput.value}}

Check this Plunker!