我只是想创建一个从现在起3天的日期,用于打字稿角度组件.
我看过Angular2时刻,但这似乎只与管道有关.虽然我确实看到这篇关于在代码中使用管道的文章,看起来有点hacky ......
也许我错过了一些东西,因为这应该很简单?!
谢谢
在我的 angular 5 应用程序中,当我使用
ng build --prod --sm
Run Code Online (Sandbox Code Playgroud)
和开源地图浏览器,moment 在 main.js 文件中占用了大量空间。我发现使用时所有语言环境都已加载
import * as moment from 'moment';
Run Code Online (Sandbox Code Playgroud)
我已经将材料力矩适配器用于应用程序中也需要力矩包的某些功能。
我已经使用 angular-cli 创建了应用程序。我发现许多使用 webpack.config.js 中的设置排除语言环境的链接有没有办法使用 angular-cli 排除语言环境?
在使用 moment 构建 angular 8 项目时,我遇到了以下错误消息:
ng build @myproject/common
Run Code Online (Sandbox Code Playgroud)
Error: Cannot call a namespace ('moment')
我在互联网上发现了类似的问题,并针对 Angular 6/7 提出了如下所述的建议解决方案。但是它们都没有为我使用 angular 8 工作。
改变常规时刻导入
import * as moment from 'moment';
Run Code Online (Sandbox Code Playgroud)
到
import * as moment_ from 'moment';
const moment = moment_;
Run Code Online (Sandbox Code Playgroud)
通过 tsconfig.json 编译器选项使用默认导入
import moment from moment;
Run Code Online (Sandbox Code Playgroud)
与tsconfig.json包括
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
......
}
Run Code Online (Sandbox Code Playgroud)
有什么办法解决这个问题吗?
ng版本
Angular CLI: 8.3.22
Node: 12.13.0
OS: win32 x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, …Run Code Online (Sandbox Code Playgroud) 我收到错误消息:
模板解析错误:找不到管道“ amDateFormat”
这是我的 app.module.ts
import { NgModule } from '@angular/core';
...
import { MomentModule } from 'angular2-moment';
...
@NgModule({
declarations: [
MyApp
],
imports: [
...
MomentModule,
...
],
bootstrap: [IonicApp],
entryComponents: [
MyApp
],
providers: [
...
]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
然后在service-booking-details.ts执行以下操作:
import { Component} from '@angular/core';
import { IonicPage, NavController, NavParams} from 'ionic-angular';
import { MomentModule } from 'angular2-moment';
...
@IonicPage()
@Component({
selector: 'page-item-detail',
templateUrl: 'service-booking-detail.html'
})
export class ServiceBookingDetailPage {
service: …Run Code Online (Sandbox Code Playgroud) 我正在 Angular 4 应用程序中工作,一切正常,直到我克隆我的存储库并运行 npm install 和 ngserve
这个错误似乎是问题所在
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (47,77): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (47,92): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (47,111): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,27): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,49): ')' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,71): Expression expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,74): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,75): Declaration or statement expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,79): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (49,32): ',' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (49,54): Expression expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts …Run Code Online (Sandbox Code Playgroud) 我在angular 5中使用了矩v2.22.0,这就是我在模块中导入它的方式-
import * as moment from 'moment';
Run Code Online (Sandbox Code Playgroud)
并将其作为-
export class ChatComponent {
.
.
.
public moment: any = moment;
.
.
}
Run Code Online (Sandbox Code Playgroud)
当我在html模板中使用它时-
<div>{{moment(activeTeam.createdAt).format('LL')}}</div>
Run Code Online (Sandbox Code Playgroud)
它给我一个错误消息,-
[Angular] Member 'moment' is not callable
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我在做什么错!