typescript – 模块’“angular2 / angular2”’没有导出成员’For’

前端之家收集整理的这篇文章主要介绍了typescript – 模块’“angular2 / angular2”’没有导出成员’For’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在关注官方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.

仍然存在错误.

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.

您的问题是文档不同步.如果您最近按照文档进行安装,那么它将安装最新版本alpha26的类型,其中包含许多破坏的更改.该文档使用该版本代码的a23版本.你也可以

1)将您的打字更新为与v23匹配的旧版本,即find it here.复制内容并将其替换为./typings/angular2/angular2.d.ts.

2)将角度脚本升级alpha 26并修复几件事.

>现在是NgFor,如果现在是NgIf
> * for现在是* ng-for,* if if now * ng-if …
> injectables(如果您打算在指令设置中使用)现在是appInjector
>使用相同的tsd查询xxx –action install命令为es6-promise,rx和rx-lite安装输入.

Demo – 23

Demo – 26

你也可以使用angular-class webpack starter的启动.

原文链接:https://www.f2er.com/angularjs/141603.html

猜你在找的Angularjs相关文章