小编Mah*_*kos的帖子

Angular 4 - 如何在输入类型中使用货币管道

我有一个HTML输入:

<input [(ngModel)]="item.value" name="inputField" type="text" />
Run Code Online (Sandbox Code Playgroud)

我想格式化它的值并使用现有的管道:

.... [(ngModel)]="item.value | currency:'USD':true" .....
Run Code Online (Sandbox Code Playgroud)

此外,我试图以下面的方式使用它,但它第一次给我理想的输出并在更新字段时显示错误:

<input type="text" 
   [ngModel]="item.value | currency:'USD':true" 
   (ngModelChange)="item.value=($event)">
Run Code Online (Sandbox Code Playgroud)

上面的代码导致以下错误.

ERROR错误:InvalidPipeArgument:''对于管道'CurrencyPipe'
在invalidPipeArgumentError(common.es5.js:2610)
处于formatPumber.webpackJsonp
.../../../common /的formatNumber(common.es5.js:3176)LandingPageComponent.webpackJsonp上的@ angular/common.es5.js.CurrencyPipe.transform(common.es5.js:3350)
.../../../../../src/app/guest-handling/landing 在handleEvent的object.eval
[as handleEvent](LandingPageComponent.html:38)的-page/landing-page.component.ts.LandingPageComponent.transformAmount(landing-page.component.ts:54)
(core.es5.js:12014) )
在callWedDebugContext(core.es5.js:13475)
的object.debugHandleEvent [as handleEvent](core.es5.js:13063)
at dispatchEvent(core.es5.js:8607)
at core.es5.js:9218

html-input angular2-ngmodel angular-pipe angular

9
推荐指数
2
解决办法
3万
查看次数

如何使用角度为2或4的D3图表

我想在我的一个项目中使用D3图表,请帮忙.

我试着按照安装过程.但它没有正常工作peasen为我提供了另一个解决方案,因此可以在现有项目中实现它.

npm install d3-ng2-service --save

import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ApplicationRef } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';

import { D3Service } from 'd3-ng2-service'; // <-- import statement

@NgModule({
  declarations: [
    AppComponent,
    TestD3Component // <-- declaration of the D3 Test component used below
  ],
  imports: [
    BrowserModule,
    CommonModule,
    FormsModule
  ],
  providers: [D3Service], // <-- provider registration
  entryComponents: [AppComponent],
  bootstrap: [AppComponent]
}) …
Run Code Online (Sandbox Code Playgroud)

charts d3.js angular

2
推荐指数
1
解决办法
9878
查看次数