所有
我对Angular2很新,比如说我定义了一个App组件和一个SubCom组件:
subcom.component.ts
@Component({
selector: 'sub-com',
template: `
<ul>
<li *ngFor="#t of target">{{t}}</li>
</ul>
`
})
export class SubCom {
@Input() target: number;
}
app.component.ts
import {Component} from 'angular2/core';
import {SubCom} from "./subcom.component";
@Component({
selector: 'my-app',
template: `
<sub-com [target]="hello"></sub-com>
`,
directives: [SubCom]
})
export class AppComponent {
hello: string[] = ["Alice", "Bob"];
}
当我运行它时,SubCom可以告诉target是数组并构建那个ngFor列表。但是我在SubCom中将目标定义为数字,为什么在转换TypeScript时没有报告错误?
由于