Angular2でインターフェイスを挿入する適切な方法があるのだろうか? (下を参照)angle2でインターフェイスを挿入することはできますか?
これは、インターフェイス上の欠けている@Injectable()デコレータと関連していると思いますが、これは許可されていないようです。
よろしくお願いいたします。
CoursesServiceInterfaceがインターフェイスとして実装されている場合は、活字体のコンパイラは "CoursesServiceInterfaceの名前を見つけることができません" 文句:
import {CoursesServiceInterface} from './CoursesService.interface';
import {CoursesService} from './CoursesService.service';
import {CoursesServiceMock} from './CoursesServiceMock.service';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
GlobalService,
provide(CoursesServiceInterface, { useClass: CoursesServiceMock })
]);
が、インターフェイスとしてCoursesServiceInterfaceと:
import {Injectable} from 'angular2/core';
import {Course} from './Course.class';
//@Injectable()
export interface CoursesServiceInterface {
getAllCourses(): Promise<Course[]>;//{ return null; };
getCourse(id: number): Promise<Course>;// { return null; };
remove(id: number): Promise<{}>;// { return null; };
}
サービスがクラスで、 TypeScriptコンパイラはもう文句を言わない:
import {Injectable} from 'angular2/core';
import {Course} from './Course.class';
@Injectable()
export class CoursesServiceInterface {
getAllCourses() : Promise<Course[]> { return null; };
getCourse(id: number) :Promise<Course> { return null; };
remove (id: number) : Promise<{}> { return null; };
}
useClass:@Injectデコレータの助けを借りて、それ、私が行方不明になった何だった...あまりにも悪いことは公式のチュートリアル – Aligned
ではありませんhttps://angular.io/docs/ts/最新/ cookbook/dependency-injection.html#!#usevalue –