node.js - How to use js function from imported npm package in angular 4 -
i'm using angular 4, here problem have proposal-list component, , use accounting-js npmjs accounting-js , link documentation how use function, installed using
npm install accounting-js here proposal-list.component.ts
import { component, oninit } '@angular/core'; import { formatnumber } 'accounting-js/lib/formatnumber.js'; @component({ selector: 'app-proposal-list', templateurl: './proposal-list.component.html', styleurls: ['./proposal-list.component.css'] }) export class proposallistcomponent implements oninit { constructor() { } ngoninit() { } } my question how can use function inside formatnumber.js?
i tried use in proposal-list.component.html
total money = {{formatnumber(1000500.65)}} but it's not showed up, no error message.
addional info problem
here app.module.ts
import { browsermodule } '@angular/platform-browser'; import { ngmodule } '@angular/core'; import { alertmodule } 'ngx-bootstrap'; import { bsdropdownmodule } 'ngx-bootstrap'; import { formsmodule } '@angular/forms'; import { appcomponent } './app.component'; import { homepagecomponent } './homepage/homepage.component'; import { approutingmodule } './app-routing.module'; import { documentscomponent } './documents/documents.component'; import { proposallistcomponent } './proposal/proposal-list/proposal-list.component'; import { proposalshowcomponent } './proposal/proposal-show/proposal-show.component'; import { proposalnewcomponent } './proposal/proposal-new/proposal-new.component'; @ngmodule({ declarations: [ appcomponent, homepagecomponent, documentscomponent, proposallistcomponent, proposalshowcomponent, proposalnewcomponent ], imports: [ alertmodule.forroot(), bsdropdownmodule.forroot(), browsermodule, approutingmodule, formsmodule ], providers: [], bootstrap: [appcomponent] }) export class appmodule { }
you should doing in ts file , if want in html have define function in ts. try this.
import { component, oninit } '@angular/core'; import { formatnumber } 'accounting-js/lib/formatnumber.js'; @component({ selector: 'app-proposal-list', templateurl: './proposal-list.component.html', styleurls: ['./proposal-list.component.css'] }) export class proposallistcomponent implements oninit { private money: number ; constructor() { } ngoninit() { this.money = formatnumber(1000500.65) } } and in html
total money = {{money}}
but if want use on fly, can create custom pipe using formatnumber function
import { pipe, pipetransform } '@angular/core'; import { formatnumber } 'accounting-js/lib/formatnumber.js'; @pipe({name: 'formatnumber'}) export class formatnumberpipe implements pipetransform { transform(money:number): number { return formatnumber(money) } } and can use like
total money = 1000500.65 | formatnumber update must include pipe in declarations array of appmodule.
app.module.ts
import { ngmodule } '@angular/core'; import { browsermodule } '@angular/platform-browser'; import { formsmodule } '@angular/forms'; import { httpmodule } '@angular/http'; import { appcomponent } './app.component'; import { formatnumberpipe} './pipe.component';// whatever name of pipe component @ngmodule({ imports: [ browsermodule, formsmodule, httpmodule ], declarations: [ appcomponent, formatnumberpipe// **<-- guy** ] ......
Comments
Post a Comment