为Angular2中的组件属性提供不同类型的数据时,为什么打字稿不报错

时间:2016-03-08 22:46:14

标签: angular

所有

我对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时没有报告错误

由于

0 个答案:

没有答案