[英]Angular 2 - how to add a custom class?
我嘗試將常規課程添加到我的項目中,但是我得到了
zone.js:917 Uncaught Error: Unexpected value 'Tools' declared by the module 'AppModule'.
Please add a @Pipe/@Directive/@Component annotation.
我只是想在項目中的某個地方使用普通的打字稿類
它不是指令,也不是管道,也不是組件
export class Tools
{
pascalCase(text:string)
{
return text.charAt(0).toUpperCase() + text.slice(1);
}
}
這是應用程序模塊
import { NgModule, ApplicationRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { CookieService } from 'angular2-cookie/core';
...
import { Tools } from './tools.class';
@NgModule({
imports: [
BrowserModule,
HttpModule,
FormsModule,
routing,
CustomErrorHandlerModule
],
declarations: [
AppComponent,
...
Tools
],
謝謝
從declarations
刪除Tools
。 如果它不是組件,指令或管道,則沒有理由添加它。
無需在工具模塊中添加工具,
declarations:
用於聲明屬於當前模塊的組件,指令,管道。 聲明中的所有內容都是彼此了解的。
因此,只需從聲明中刪除Tools
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.