我正在尝试将 Angular2 与 system.js 和 typescript 一起使用。到目前为止,它对于我一直在导出的接口(interface)一直运行良好,但是一旦我尝试导入一个枚举,它就会全部崩溃。在下面的代码中,Card
工作正常,但是当我导入 Legend
时,出现错误 GET http://localhost:3000/shared/legend 404 (Not找到)
。
import {Component, OnInit} from 'angular2/core';
import {CardService} from './card.service';
import {Card} from '../../shared/card';
import {Legend} from '../../shared/legend';
@Component({
selector: 'cards-list',
templateUrl: 'app/cards-list.html',
providers: [CardService]
})
export class CardsListComponent implements OnInit {
public cards:Card[];
//using Legend is the problem!
public legendValues:String[] = [Legend[Legend.ARIANE]];
constructor(private _cardService:CardService) {
}
getCards() {
this._cardService.getCards(cards => this.cards = cards);
}
ngOnInit() {
this.getCards();
}
}
这是图例文件:
export enum Legend {
THE_RAPTOR,
LINZA,
ARIANE,
OZAN
}
为什么我不能导入普通枚举?
最佳答案
It's been working fine for the interfaces I've been exporting so far, but as soon as I try to import an enum it all blows up
接口(interface)是一个仅在编译时构造,因此没有运行时影响。具有接口(interface)的文件不会在运行时加载。然而,具有运行时内容的文件如classes
/variables
/enums
等在运行时加载,你会得到一个404这些。这是服务器设置错误。您需要允许加载这些 JS 文件。
关于angular - 如何使用 systemjs 和 Angular2 导出 typescript 枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34582258/