Angular2.o0装饰器的问题

时间:2015-12-16 21:34:55

标签: angular angular2-directives

我似乎无法对Angular2.0进行测试。每次我使用注入器装饰器时,我都会收到有关丢失文件/垫片的错误。使用类装饰器';

时需要reflect-metadata垫片

我已尝试导入我的方式

 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"
 }
}

2 个答案:

答案 0 :(得分:1)

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

/// <reference path="../../type-definitions/reflect-metadata.d.ts"" />
require("reflect-metadata");

答案 1 :(得分:0)

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

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

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