angular - Angular2 NgModel ViewModel -
i trying create directive convert number percentage example
number / 100
but don't want user see example 5/100 = 0.05 in model want see 5
this example: user sees 5.12/ it's value send in backend should changed 5.12/100
my code looks this
import { directive, hostlistener, elementref, oninit } '@angular/core'; import { ngmodel } '@angular/forms'; @directive({ selector: '[topercentage]', providers: [ngmodel] }) export class topercentagedirective implements oninit { constructor(private element: elementref, private ngmodel: ngmodel) { } ngoninit() { console.log("init"); this.ngmodel.valuechanges.subscribe(function (value){ var percent = value / 100; $(this.element.nativeelement).data("newvalue",percent); console.log(percent) }); $(this.element.nativeelement).bind("customevent", function(newval){ this.ngmodel.update.emit(newval); });
}
how achieve ?
when comes backend multiplied *100 , when goes backend divided /100
Comments
Post a Comment