Angularjs bi directional binding data input input multiple decimal points (bi directional binding does not refresh)

Time:2020-9-26

1. Introduce the changedetector ref component

import {ChangeDetectorRef} from '@angular/core'; constructor(public changeDetectorRef:ChangeDetectorRef) {}

2. Page code

<input  type="text" placeholder="0.00" \[(ngModel)\]="item.TMP\_STOCK" (ngModelChange)="inputRule('stock',$event)"/>

3. When the input box changes, execute the following method

//Trigger method when ngmodel changes 
inputRule(name, event) { 
    //When input 1 in the input box, the system thinks it is only 1 by default. At this time, ngmodel does not change, so we need to change it manually 
    this.item.TMP\_STOCK = null; 
    //Detectchanges () - performs a change detection from the component to each subcomponent
    this.changeDetectorRef.detectChanges(); 
    //Finally, assign a value to ngmodel 
    this.item.TMP\_STOCK = this.pubtool.numRule(event); 
}

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]