Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs |官方指南坏了?| Can#x27;t绑定到';ngFor';因为它不是';这不是已知的本地财产_Angularjs_Angular_Ngfor_Angular Decorator - Fatal编程技术网

Angularjs |官方指南坏了?| Can#x27;t绑定到';ngFor';因为它不是';这不是已知的本地财产

Angularjs |官方指南坏了?| Can#x27;t绑定到';ngFor';因为它不是';这不是已知的本地财产,angularjs,angular,ngfor,angular-decorator,Angularjs,Angular,Ngfor,Angular Decorator,今天我使用的是Angular2的最新版本,并遵循Angular2网站上的官方示例我正在尝试使用*ngFor解析数组,并获得以下异常模板解析错误:无法绑定到“ngFor”,因为它不是已知的本机属性

今天我使用的是Angular2的最新版本,并遵循Angular2网站上的官方示例
我正在尝试使用
*ngFor
解析数组,并获得以下异常
模板解析错误:无法绑定到“ngFor”,因为它不是已知的本机属性
谁能告诉我哪里出了问题。
谢谢

app.component.ts
从'angular2/core'导入{Component};
出口级英雄{
id:编号;
名称:字符串;
}
@组成部分({
选择器:“我的应用程序”,
模板:`
{{title}}
我的英雄
{{hero.name}}详细信息 身份证件: {{hero.id} 姓名: `, }) 导出类AppComponent{ 标题=‘英雄之旅’ hero:hero={id:1,名称:'Windstorm'}; 公众英雄=英雄; } 康斯特英雄:英雄[]=[ {id:11,姓名:'尼斯先生'}, {id:12,名字:'毒品'}, {id:13,名字:'炸弹男孩'}, {id:14,姓名:'Dr.Deseract'}, {id:15,姓名:'Mistique小姐'}, {id:16,名称:'codeopolos'}, {id:17,名字:'朱庇塔里奥'} ];
boot.ts
///
从'angular2/platform/browser'导入{bootstrap};
从“/app.component”导入{AppComponent};
bootstrap(AppComponent);

您必须
从库中导入
ngFor


从'@angular/common'导入{FORM_指令,NgFor,NgIf}

您必须
从库中导入
ngFor


从'@angular/common'导入{FORM_指令,NgFor,NgIf}

发生此错误是因为您使用的是已弃用的angular 2版本。我可以通过你导入角度模块的方式来判断

在较新版本上,不再需要导入ngFor或ngIf


除此之外,没有理由使用发布候选版本之前的任何版本构建任何内容。

发生此错误是因为您使用的是angular 2的不推荐版本。我可以通过你导入角度模块的方式来判断

在较新版本上,不再需要导入ngFor或ngIf


除此之外,没有理由在发布候选版本之前使用任何版本构建任何内容。

感谢您的洞察力,我在Angular上运行了一个旧版本。现在工作正常。

感谢您的洞察力,我在Angular上运行了一个旧版本。现在可以正常工作。

您正在使用RC之前的angular版本,在尝试解决代码中的任何潜在问题之前,我强烈建议您更新到最新版本RC4。您正在使用RC之前的angular版本,在尝试解决代码中的任何潜在问题之前,我强烈建议您更新到最新版本RC4。
import {Component} from 'angular2/core';

export class Hero {
  id:number;
  name:string;
}


@Component({
  selector: 'my-app',
  template: `
        <h1>{{title}}</h1>
        <h2>My Heroes</h2>
        <ul class="heroes">
          <li *ngFor="let hero of heroes">

          </li>
        </ul>
        <h2>{{hero.name}} details</h2>
        <div><label>id: </label>
        {{hero.id}}</div>
        <div><label>name: </label>
        <input [(ngModel)] = "hero.name" 
        placeholder="Hero Name">
        </div>
    `,
})


export class AppComponent {
  title = 'Quest of Heroes'
  hero:Hero = {id: 1, name: 'Windstorm'};

  public heroes = HEROES;
}

const HEROES:Hero[] = [
  {id: 11, name: 'Mr. Nice'},
  {id: 12, name: 'Narco'},
  {id: 13, name: 'bombboy'},
  {id: 14, name: 'Dr. Deseract'},
  {id: 15, name: 'Miss. Mistique'},
  {id: 16, name: 'codeopolos'},
  {id: 17, name: 'jupitarious'}
];
///<reference path="../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from "./app.component";
bootstrap(AppComponent);