我正在关注构建组件的basic angular2 tutorial。 Component使用以下接口:
// app/person.ts
export interface Person {
name: string;
weight: number;
height: number;
}
我决定删除export
界面前面的Person
关键字,看看会发生什么。我没有收到任何错误,应用程序正常工作。这是为什么? (是的,我保存了文件 - 开发环境采用自动重新加载。)如果我在应用程序中删除任何类前面的export关键字,我会收到错误。
感谢。
// app/people.service.ts
import { Component } from '@angular/core';
import { Person } from './person'
import { PeopleService } from './people.service'
@Component({
selector: 'people-list',
template: `
<ul>
<li *ngFor="let person of people">
{{ person.name }}
</li>
</ul>
`,
})
export class PeopleListComponent {
/*
people: Person[] = [
{name: 'Luke Skywalker', height: 70, weight: 140},
{name: 'Darth Vader', height: 80, weight: 160},
{name: 'Hans Solo', height: 85, weight: 170},
];
*/
people: Person[] = []
constructor(private _peopleService: PeopleService) {
this.people = _peopleService.getAll();
}
}