【发布时间】:2015-06-11 01:45:42
【问题描述】:
我正在关注Angular2官方网站上的教程。
https://angular.io/docs/js/latest/guide/displaying-data.html
这是我的 .ts 文件:
/// <reference path="typings/angular2/angular2.d.ts" />
import {Component, View, bootstrap, For} from 'angular2/angular2';
@Component({
selector: 'display'
})
@View({
template: '<p>name: {{myName}}</p>' +
'<p>Friends:</p>' +
'<ul>'+
'<li *for="#name of names">'+
'{{name}}'+
'<li>'+
'<ul>',
directives: [For]
})
class DisplayComponent{
myName: string;
names: Array<string>;
constructotr(){
this.myName = "Alice";
this.names = ["Winston", "Alex", "Shannon", "Irizu"];
}
}
bootstrap(DisplayComponent);
这是我的html:
<html>
<head>
<script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script>
<script src="https://jspm.io/system@0.16.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.23/angular2.dev.js"></script>
</head>
<body>
<display></display>
<script>
System.import('show-properties');
</script>
</body>
</html>
我已经安装了 angular2、Rx 和 es6-promise。
错误仍然存在。
消息 TS6042:编译完成。监视文件更改。 消息 TS6032:检测到文件更改。开始增量 编译... show-properties.ts(2,37): error TS2305: Module '"angular2/angular2"' 没有导出成员 'For'。消息 TS6042: 编译完成。监视文件更改。
更新
这是我更新的 .ts 代码:
/// <reference path="typings/angular2/angular2.d.ts" />
import {
ComponentAnnotation as Component,
ViewAnnotation as View, bootstrap, NgFor
} from 'angular2/angular2';
@Component({
selector: 'display'
})
@View({
template: '<p>name: {{myName}}</p>' +
'<p>Friends:</p>' +
'<ul>'+
'<li *ng-for="#name of names">'+
'{{name}}'+
'<li>'+
'<ul>',
directives: [NgFor]
})
class DisplayComponent{
myName: string;
names: Array<string>;
constructotr(){
this.myName = "Alice";
this.names = ["Winston", "Alex", "Shannon", "Irizu"];
}
}
bootstrap(DisplayComponent);
angular2.d.ts 仍然是 alpha 26。
现在没有错误信息了,我可以看到
名称: 朋友们:
但是没有插入任何值。 我收到一条错误消息:
show-properties.ts(7,2):错误 TS2348:“typeof”类型的值 ComponentAnnotation ' 不可调用。您的意思是包括“新”吗? show-properties.ts(10,2):错误 TS2348:“typeof”类型的值 ViewAnnotation' 不可调用。您的意思是包括“新”吗? 消息 TS6042:编译完成。监视文件更改。
【问题讨论】:
标签: typescript angular typescript1.5