javascript - Using nativescript converters -
im trying hooks nativescript javascript , have basic question:
let costformatter= { toview(value){ console.log('got:' + value); return '$' + value; }, tomodel(value){ console.log('got:' + value); return '$' + value; } }; http.getjson("<my api call>").then(function (r){ page.bindingcontext = { deals: r, costformatter:costformatter }; }, function (e){ //// argument (e) error! //console.log(e); });
in above code, define cost formatter want $ added beside price on every sale price on listview labels. render list view im using:
<listview id="steamitems" items="{{ deals }}"> <listview.itemtemplate> <gridlayout columns="*, *, 50, 50" rows="50, 50, auto, *"> <image src="{{ thumb }}" row="0" col="0" cssclass="thumb"/> <label text="{{ title }}" key="1" row="0" col="1" cssclass="title"/> <label text="{{ normalprice|costformatter }}" key="2" row="0" col="2" cssclass="normal-price"/> <label text="{{ saleprice|costformatter }}" key="3" row="0" col="3" cssclass="sale-price"/> </gridlayout> </listview.itemtemplate> </listview>
i not understand why
js: cannot find function or filter: costformatter
for each row in listview in nativescript terminal. doing wrong?
it seems you're trying create so-called 'pipe'.
import { pipe, pipetransform } '@angular/core'; @pipe({ name: 'costformatter', pure: true }) export class costformatterpipe implements pipetransform { transform(price: string): string { return "$ " + price; } }
then make sure add costformatterpipe
declarations
array of module want use in.
Comments
Post a Comment