Limit input field to two decimal places - Angular 5
问题 The code is as follows <input type="number" class="form-control" value="" name="cost_price" #name="ngModel" [(ngModel)]="item.cost_price" placeholder="Cost Price" /> User should not be able to type more that 2 decimal places. For example, if the user wants to enter 21.256. He should be only allowed to enter 21.25 How to achieve this using angular 5? 回答1: First create Directive for limit the two decimal places in typescript like this: import { Directive, ElementRef, HostListener } from '