2017-09-15 25 views
0

私は単純なBean/DTOクラスになりたいいくつかのクラスを持っていますが、それらは@componentクラスを表示せず、@Pipeクラスでもなく、@Directiveでなければなりません(少なくとも私は考えませんそのはず!)。モデルクラスをAngularモジュールに含めるにはどうすればよいですか?

私は(彼らは他のモジュールにまたがって使用されます)モジュールにそれらをバンドルすることができるようにしたいが、いくつかの呪文にもかかわらず、私はこのようなエラーを得続ける:

私は(NGサーブ)私の角度のアプリを起動するときそれは大丈夫コンパイルしますが、ブラウザ(クローム)コンソールで、私はエラーを取得します....

Uncaught Error: Unexpected value 'Accreditation' declared by the module 'ServiceModule'. Please add a @Pipe/@Directive/@Component annotation. 

私は他のモジュールが使用するモジュールの中に、これらのクラスをバンドルする必要がありますどのように?彼らが私のサービスモジュールに入っているのか、別の新しい 'beans'モジュールに入っているのかは気にしません。

を考えると、このモジュール定義(service.module.ts):

import { NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import {MemberService} from "./member/member.service"; 
import { Accreditation } from "./accreditation"; 
import {Player} from "./player"; 
import {Club} from "./club"; 
import {Coach} from "./coach"; 

@NgModule({ 
    imports: [CommonModule], 
    declarations: [Accreditation, Club, Player, Coach], 
    exports: [Accreditation, Club, Player, Coach], 
    providers: [MemberService] 
}) 
export class ServiceModule { } 

accreditation.ts:

export class Accreditation { 
    uuid: string; 
    name :string; 
    lastComplete: Date; 
    expires: Date; 
    inLast6Months: boolean; 
    type: String; 
    displayName: String; 
    hasCompleted: boolean; 
} 
+1

基本DTOのは、「角度物事ので、ドンはありませんtはAngularモジュールに属します。宣言配列に追加することはできません。宣言配列は、コンポーネント、ディレクティブ、およびパイプのみのため、表示されるエラーです。 – DeborahK

答えて

0

インポートでもないapp.moduleであなたのモデルクラスを宣言する必要はありません.ts。それはあなたのコンポーネント、ディレクティブなどで輸入として使用可能なオブジェクトです。.. は、単にいずれかのコンポーネント/サービスにそれをインポート/あなたが他の輸入で必要なディレクティブ:

import { Accreditation } from "./accreditation"; 
関連する問題