我创建了一个简单的Hello World应用程序,工作正常.但是当我想添加一个“服务”只是一个简单的迪我得到以下错误:
angular2.dev.js:23877 EXCEPTION:无法解析“AppComponent”(?)的所有参数.确保所有参数都使用“注入”或“有效”类型注释进行装饰,“AppComponent”使用“可注入”进行装饰.
angular2-polyfills.js:469未处理的承诺拒绝:无法解析“AppComponent”(?)的所有参数.确保所有参数都使用“注入”或“有效”类型注释进行装饰,“AppComponent”使用“可注入”进行装饰. ;区域:角度任务:承诺值:
我有3个文件
boot.ts:
///<reference path="../../node_modules/angular2/typings/browser.d.ts"/> import {bootstrap} from 'angular2/platform/browser' import {AppComponent} from './mainApp' bootstrap(AppComponent);
mainApp.ts:
import {Component} from 'angular2/core'; import {CourseService} from './course.service'; @Component({ selector: 'my-app',template: 'My First Angular 2 App',providers: [CourseService],}) export class AppComponent { constructor(courseService: CourseService) { } }
course.service.ts:
export class CourseService { public getCourses(): string[] { let courses: string[] = ["Course 1","Course 2","Course 3"]; return courses; } }
这是我的HTML文档的头,我使用角度2 beta 13:
<script src="~/Scripts/es6-shim.min.js"></script> <script src="~/Scripts/system-polyfills.js"></script> <script src="~/Scripts/shims_for_IE.js"></script> <script src="~/Scripts/angular2-polyfills.js"></script> <script src="~/Scripts/system.js"></script> <script src="~/Scripts/Rx.js"></script> <script src="~/Scripts/angular2.dev.js"></script> <!-- 2. Configure SystemJS --> <script> System.config({ packages: { 'ScriptsApp/views': { defaultExtension: 'js' } } }); </script> <script> System.import('ScriptsApp/views/boot').then(null,console.error.bind(console)); </script>
更新这些是现在我修复的csproj TypeScript设置
<TypeScriptTarget>ES5</TypeScriptTarget> <TypeScriptJSXEmit>None</TypeScriptJSXEmit> <TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled> <TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny> <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind> <TypeScriptRemoveComments>False</TypeScriptRemoveComments> <TypeScriptOutFile /> <TypeScriptOutDir /> <TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations> <TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError> <TypeScriptSourceMap>True</TypeScriptSourceMap> <TypeScriptMapRoot /> <TypeScriptSourceRoot /> <TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators> <TypeScriptEmitDecoratorMetadata>True</TypeScriptEmitDecoratorMetadata>
在最新VS 2015更新中,您还可以使用tsconfig.json,然后忽略TypeScript的解决方案设置.我目前的例子,我的tsconfig.json:
{ "compilerOptions": { "target": "es5","module": "commonjs","moduleResolution": "node","sourceMap": true,"emitDecoratorMetadata": true,"experimentalDecorators": true,"removeComments": false,"noImplicitAny": false,//Kümmert sich um die Typings das diese entsprechend gefunden werden,keine Reference mehr in boot.js notwendig. Geht aber in VS nicht! //"lib": ["es6"],"types": [ "node" //wird für RequireJs benötigt,damit z.b. der Typ gefunden werden kann ] },//Wird für den AwesomeTypeScriptLoad in WebPack benötigt! "awesomeTypescriptLoaderOptions": { "useWebpackText": true },"exclude": [ "node_modules","dist","typings/main","typings/index.d.ts" ],"compileOnSave": true }