Adnan Fayaz
Adnan Fayaz

Reputation: 167

how to call a function from a dropdown menu in angular4

** I ve two functions in my component.ts. 1) getfixedbyId(val) 2) getFloatById(val). but I'm not able to call them through this method. Dont want to use controllers.**

<select class="form-control" formControlName="propertyId">
  <option value="">--Select Property -- </option>
    <ng-container *ngIf="subForm.controls.subscriptiondetails.controls.selecttype.value==='Somethging1'" ng-click="getFloatByID(property.someId)">
      <option *ngFor="let property of floatList" [(value)]="property.floatingId"  >{{property.name}}</option>
    </ng-container>
    <ng-container *ngIf="subForm.controls.subscriptiondetails.controls.selecttype.value==='Something2'" ng-click="getFixedByID(property.someId)">
      <option *ngFor="let property of fixedList" [(value)]="property.fixedId" >{{property.name}}</option>
   </ng-container>

 </select> 

Upvotes: 0

Views: 73

Answers (2)

Pardeep Jain
Pardeep Jain

Reputation: 86750

Just replace your way of calling a method in Angular like this -

ng-click

with

(click)

Upvotes: 1

AntonioGarc&#237;a
AntonioGarc&#237;a

Reputation: 1150

You are using the old AngularJS syntax for the click action. You should use the new Angular syntax like this:

<ng-container *ngIf="subForm.controls.subscriptiondetails.controls.selecttype.value==='Somethging1'" (click)="getFloatByID(property.someId)">

If you need more information about it you can read all about the click syntax in the docs.

Upvotes: 1

Related Questions