首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模块‘angular2 2/angular2 2’没有导出成员'For‘

模块‘angular2 2/angular2 2’没有导出成员'For‘
EN

Stack Overflow用户
提问于 2015-06-11 01:45:42
回答 2查看 16.9K关注 0票数 7

我正在遵循官方Angular2网站上的教程。

https://angular.io/docs/js/latest/guide/displaying-data.html

这是我的.ts文件:

代码语言:javascript
复制
/// <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:

代码语言:javascript
复制
<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-承诺。

但错误仍然存在。

消息TS6042:编译完成。监视文件更改。消息TS6032:检测到文件更改。开始增量编译..。S(2,37):错误TS2305:模块‘angular2/angular2’‘没有expo成员'For’。消息TS6042:编译完成。监视文件更改。

更新

下面是我更新的.ts代码:

代码语言:javascript
复制
/// <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。

现在没有错误消息,我可以看到

姓名:朋友:

但是没有插入任何值。我收到一条错误信息:

T(7,2):error TS2348:类型‘type of ComponentAnnotation’的值不可调用。你的意思是包括“新”吗?T(10,2):error TS2348:类型‘type of ViewAnnotation’的值不可调用。你的意思是包括“新”吗?消息TS6042:编译完成。监视文件更改。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-11 02:15:25

您的问题是文档不同步。如果您最近遵循了安装的文档,那么它就会安装最新版本的alpha26的类型,该版本有很多错误的更改。文档将a23版本与该版本的代码一起使用。你可以

1)将您的类型更新为与v23匹配的旧版本,您可以在这里找到它。复制内容并在./typings/angular2/angular2.d.ts中替换它。

2)将您的角脚本升级到阿尔法26,并修复两件事。

  • For现在是NgForIf现在是NgIf
  • *for现在是*ng-for *if现在是*ng-if ..。
  • injectables (如果您打算在指令设置中使用)现在是appInjector
  • 使用相同的es6-promise命令安装rxrx-litetsd query xxx --action install类型。 演示- 23 演示- 26

您还可以使用来自角级webpack起动器的启动。

票数 13
EN

Stack Overflow用户

发布于 2015-06-11 05:11:10

是的,改名为ng-for。如果是这样的话。只需在ts文件和视图中更新它。

如果您对一些工作角度2.0示例感兴趣,这里有一些示例:http://www.syntaxsuccess.com/viewarticle/angular-2.0-examples

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30770222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档