角材料matautocomplete实际上选择值

时间:2018-08-03 17:30:24

标签: angular forms angular-material

我遇到一个问题,即表单在自动填充后无法选择该值。

它确实会自动填充状态,但由于使用[Validators.required]时表单无效,因此好像没有选择状态。

想知道是否有办法实际选择输入值。

enter image description here

component.html

       <mat-form-field>
             <input type="text" placeholder="State" matInput formControlName="state"
            [matAutocomplete]="auto" required>
                <mat-autocomplete #auto="matAutocomplete" dropdown-arrow="true" (optionSelected)="state.name">
                    <mat-option *ngFor="let state of states" [value]="state.name">{{state.name}}</mat-option>
                </mat-autocomplete> 
        </mat-form-field>

component.ts

    this.shippingForm = this.formBuilder.group({
        userName: [''],
        password: [''],
        firstName: ['', [Validators.required]],
        lastName: ['', [Validators.required]],
        address1: [],
        address2: [],
        city: [, [Validators.required]],
        country: ['',  [Validators.required]],
        postalCode: [,  [Validators.required]],
        state: [,  [Validators.required]],
        phone: [,  [Validators.required]],
        email: [,  [Validators.required, Validators.email]],
    });

1 个答案:

答案 0 :(得分:0)

test's
new line 
"quote"

if(isset($_POST['submit']) && !empty($_POST['email'])){ //Process form $name = $_POST['name']; $name = mysql_prep($name); $email = $_POST['email']; $email = mysql_prep($email); $message = $_POST['message']; $message = mysql_prep($message); $emailto = "client_email1@gmail.com,client_email2@gmail.com"; $subject = "Message from '$name'"; // the message $message = "<html><body> <h3>Title</h3> From: $name<br> Email: $email<br><br> Message:<br> $message<br><br> </body></html>"; //headers make the mail() work $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($emailto, $subject, $message, $headers); 上调用一个函数,然后尝试查看<mat-autocomplete #auto="matAutocomplete" dropdown-arrow="true" (optionSelected)="getStateName($event.option.value)"> optionSelect()中的值。一旦有了价值,就可以对其进行进一步的操作