typescript - 在 Angular 2 中带参数的组件基本降级会报错: (SystemJS) 无法解析所有参数
出于某种原因,当我将一个只有1个输入参数的简单组件降级时,我会收到此消息:
(SystemJS) 无法解析 MyLabelComponent 的所有参数:(?)。
没有任何参数的相同组件也能正常工作。哪里出了问题?我是不是漏了什么?我按照 angular.io 的教程,把 Angular 2 组件降级以在 Angular 1 应用中使用,做了所有步骤。
my-label.component.ts
import { Component, OnInit, Input, ElementRef } from '@angular/core';
@Component({
selector: 'my-label',
templateUrl: './my-label.component.html',
styleUrls: ['./my-label.component.css']
})
export class MyLabelComponent implements OnInit {
@Input() text: string;
constructor(private elementRef: ElementRef) { }
ngOnInit() {
}
}
my-label.component.html
<div class="my-label">{{text}}</div>
my-label.component.css
.my-label { color: red; }
app.module.ts
import { MyLabelComponent } from './my-label/my-label.component';
@NgModule({
declarations: [
AppComponent,
MyLabelComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
UpgradeModule
],
entryComponents: [
MyLabelComponent
],
bootstrap: [AppComponent]
})
export class AppModule {}
import * as _angular_ from 'angular';
declare global {
const angular: typeof _angular_;
}
import { downgradeComponent } from '@angular/upgrade/static';
angular.module('myModule')
.directive('myLabel', downgradeComponent({component: MyLabelComponent, inputs: ['text']}) as angular.IDirectiveFactory);
