0

我似乎无法Angular2.0接受测试。每次我使用注入器装饰器时,都会收到有关缺少文件/垫片的错误。reflect-metadata使用类装饰器时需要 shim;

我已经尝试过导入我的方式

 import {CalendarBuilder} from './CalendarBuilder';
 import 'reflect-metadata';
 import 'zone.js'

但是没有 Angular 说不喜欢。

这是我的包的内容 - 一个修改过的 AngularExample,它需要修剪。任何人都可以请帮忙吗?

{   
"name": "angular2-quickstart",   
"version": "1.0.0",   
"scripts": {
     "test": "live-server --open=app/unit-tests.html",
     "tsc": "tsc",
     "tsc:w": "tsc -w",
     "lite": "lite-server",
     "go": "concurrent \"npm run tsc:w\" \"npm run lite\" "
},   
 "license": "ISC",
 "dependencies": {
     "angular2": "2.0.0-alpha.53",
     "chai": "^3.4.1",
     "es6-promise": "^3.0.2",
     "es6-shim": "^0.33.3",
     "gulp": "^3.9.0",
     "reflect-metadata": "^0.1.2",
     "rxjs": "5.0.0-alpha.14",
     "systemjs": "0.19.6",
     "underscore": "^1.8.3",
     "zone.js": "^0.5.8"   },
     "devDependencies": {
     "concurrently": "^1.0.0",
     "es6-shim": "^0.33.13",
     "gulp-jasmine": "^2.2.1",
     "gulp-mocha": "^2.2.0",
     "jasmine-core": "2.4.1",
     "jspm": "^0.16.18",
     "lite-server": "^1.3.1",
     "live-server": "^0.9.0",
     "requirejs": "^2.1.22",
     "system-npm": "^0.4.2",
     "typescript": "^1.7.3"
 }
}
4

2 回答 2

1

我通过导入npm包并引用测试顶部的类型定义解决了这个问题:

/// <reference path="../../type-definitions/reflect-metadata.d.ts"" />
require("reflect-metadata");
于 2015-12-17T10:57:12.737 回答
0

您可以通过包含 Angular 2 提供的 polyfill 来解决缺少的问题。zone.js将其放入您的 index.html 文件中:reflect-metadata

<script src="../node_modules/angular2/bundles/angular2-polyfills.min.js"></script>

您可能必须更改路径以适应您的特定设置,但重要的是要知道脚本位于文件夹的angular2/bundles部分中。node_modules

于 2015-12-17T03:34:57.127 回答