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.
仍然存在错误.
message TS6042: Compilation complete. Watching for file changes.
message TS6032: File change detected. Starting incremental
compilation… show-properties.ts(2,37): error TS2305: Module
‘”angular2/angular2″‘ has no expo rted member ‘For’. message TS6042:
Compilation complete. Watching for file changes.
更新
这是我更新的.ts代码:
/// <reference path="typings/angular2/angular2.d.ts" /> import { ComponentAnnotation as Component,ViewAnnotation as View,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","Irizu"]; } } bootstrap(DisplayComponent);
angular2.d.ts仍然是alpha 26.
现在没有错误消息,我可以看到
名称:
好友:
但是没有插入任何值.
我收到一条错误消息:
show-properties.ts(7,2): error TS2348: Value of type ‘typeof
ComponentAnnotation ‘ is not callable. Did you mean to include ‘new’?
show-properties.ts(10,2): error TS2348: Value of type ‘typeof
ViewAnnotation’ is not callable. Did you mean to include ‘new’?
message TS6042: Compilation complete. Watching for file changes.
1)将您的打字更新为与v23匹配的旧版本,即find it here.复制内容并将其替换为./typings/angular2/angular2.d.ts.
>现在是NgFor,如果现在是NgIf
> * for现在是* ng-for,* if if now * ng-if …
> injectables(如果您打算在指令设置中使用)现在是appInjector
>使用相同的tsd查询xxx –action install命令为es6-promise,rx和rx-lite安装输入.
你也可以使用angular-class webpack starter的启动.