问题描述
您好我下面的官方Angular2网站上的教程。
https://angular.io/docs/js/latest/guide/displaying-data.html
下面是我的TS文件
///<参考路径=分型/ angular2 / angular2.d.ts/>
进口{组件,视图,引导,对于}的'angular2 / angular2';@零件({
选择:'显示'
})
@视图({
模板:'< P>名称:{{} MYNAME}< / P>' +
'< P>朋友:LT; / P>' +
'< UL>'+
'<李*的= GT的名字#名;+
{{名}}'+
'<立GT;'+
'&所述; UL>',
指令:[供]
})
类DisplayComponent {
MYNAME:字符串;
名称:数组<字符串取代; constructotr(){
this.myName =爱丽丝;
this.names =温斯顿,亚历克斯,香,Irizu];
}
}引导(DisplayComponent);
下面是我的html:
< HTML和GT;
< HEAD>
&LT;脚本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&GT;&下; /脚本&GT;
&LT;脚本SRC =HTTPS://$c$c.angularjs.org/2.0.0-alpha.23/angular2.dev.js&GT;&LT; / SCRIPT&GT;
&LT; /头&GT;
&LT;身体GT;
&lt;显示&GT;&LT; /显示&GT;
&LT;脚本&GT;
System.import('显示的属性');
&LT; / SCRIPT&GT;
&LT; /身体GT;&LT; / HTML&GT;
和我已经安装了angular2,Rx和ES6-承诺。
不过的错误仍然存在。
Update
Here is my updated ts code:
/// <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 is still the alpha 26.
Now there is no error message and I can seename:Friends:
But no values are inserted.And I got an error message:
Your issue is that the documentation is not in sync. If you followed the documentation for installation recently then it would have installed the typings for latest version alpha26, which has a lot of broken changes. And the documentation uses a23 version with that version of code. You can either
1) Update your typings to older version that matches v23, which you can find it here. Copy the contents and replace it in ./typings/angular2/angular2.d.ts
.
2) Upgrade your angular script to alpha 26 and fix couple of things.
For
is nowNgFor
,If
is nowNgIf
*for
is now*ng-for
,*if
is now*ng-if
...injectables
(if you intend to use in your directive settings) is nowappInjector
install typings for
es6-promise
,rx
andrx-lite
using the sametsd query xxx --action install
command.
You could also use the startup from angular-class webpack starter.
这篇关于模块'&QUOT; angular2 / angular2&QUOT;'没有出口成员“对于'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!