根据 https://angular.io/docs/js/latest/guide/displaying-data.html 一步一步做, 在引用类上出了问题.
TypeScript 编译:
tsc --watch -m commonjs
"compilerOptions": {
"emitDecoratorMetadata": true,
"module": "amd",
"target": "es5"
}
原始代码为:
///
import {Component, View, bootstrap, NgFor} from 'angular2/angular2';
@Component({
selector: 'display',
appInjector: [FriendsService]
})
@View({
template: `
My name is {{ myName }}
Friends:
-
{{ name1 }}
`,
directives: [NgFor]
})
class DisplayComponent {
myName: string;
names: Array;
constructor(friendsService: FriendsService) {
this.myName = 'Alice';
this.names = friendsService.names;
}
}
class FriendsService {
names: Array;
constructor() {
this.names = ["Alice", "Aarav", "Martín", "Shannon", "Ariana", "Kai"];
}
}
bootstrap(DisplayComponent);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
把 FriendsService 搬上去就可以了
https://github.com/kittencup/angular2-ama-cn/issues/11 有具体的解决方案