0

Hey i have form in my project and i try to send to value of mat-select

my html:

  <mat-form-field class="input-class" appearance="fill">
            <mat-label>בחר שותף <i class="far fa-id-card"></i></mat-label>
            <mat-select placeholder="בחר שותף">
                <mat-option value="partner" #partnerValue *ngFor="let partner of partnersData">{{partner}}</mat-option>
            </mat-select>
        </mat-form-field>
   <div class="col-sm">
        <button class="aproveBtn" (click)="submitForm(partnerValue)">Create</button>
    </div>

my ts file:

  submitForm(partner) {
    console.log(partner);
  }

its console undefiend or error what is the problem??

3
  • 2
    <mat-select #partnerValue placeholder="בחר שותף"> & (click)="submitForm(partnerValue.value)" Commented Oct 2, 2019 at 11:45
  • 1
    we have [(value)] to get the two way binding Commented Oct 2, 2019 at 11:52
  • Its not work, it console "partner" and not the original value that selected Commented Oct 2, 2019 at 11:54

2 Answers 2

1

You can use angulars two way binding:

 <mat-select [(value)]="selectedPartner">
...
 <button class="aproveBtn" (click)="submitForm(selectedPartner)">Create</button>

Have a look at the angular materials select API for more examples.

A Stackblitz from the docs which uses 2-way value binding.

Sign up to request clarification or add additional context in comments.

Comments

0

You can modify your html file as-

<mat-form-field class="input-class" appearance="fill">
            <mat-label>בחר שותף <i class="far fa-id-card"></i></mat-label>
            <mat-select #partnerValue placeholder="בחר שותף">
                <mat-option [value]="partner"  *ngFor="let partner of partnersData">{{partner}}</mat-option>
            </mat-select>
        </mat-form-field>
   <div class="col-sm">
        <button class="aproveBtn" (click)="submitForm(partnerValue.value)">Create</button>
    </div>

Here is a stackblitz demo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.