Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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
Html 角度2*Ng,用于不显示数据_Html_Typescript_Angular - Fatal编程技术网

Html 角度2*Ng,用于不显示数据

Html 角度2*Ng,用于不显示数据,html,typescript,angular,Html,Typescript,Angular,我似乎无法获取此中的数据。要在列表中显示的英雄。我发出了一个警报(this.heromes[0].name)并且它确实显示了数据,所以这个正在返回数据 app.html <div style="width:1000px;margin:auto"> <ul> <li *ngFor="#hero of heroes"> <span>{{hero.name}}</span> &l

我似乎无法获取此中的数据。要在列表中显示的英雄。我发出了一个警报(this.heromes[0].name)并且它确实显示了数据,所以这个正在返回数据

app.html

<div style="width:1000px;margin:auto">
    <ul>
        <li *ngFor="#hero of heroes">
            <span>{{hero.name}}</span>
        </li>
    </ul>
</div>

先试试这个,看看它是否有效:

<li ng-repeat="hero in heroes">
    {{hero.name}}
</li>
  • {{hero.name}

  • 如果这样做有效,您可能会有一个旧的angular版本,它还不支持*ngFor语法(我认为新版本angular 2支持这种语法)。

    我做了更多的研究,没有显示任何数据。例如:

    <h2>My favorite hero is {{ myHero }}</h2>
    
    我最喜欢的英雄是{{myHero}
    
    获取一个空行(其中myHero是填充的字符串),而

    我最喜欢的英雄是
    
    显示

    我最喜欢的英雄是


    我将更改Angular 2的Beta版,看看它是否有帮助

    您将
    警报()放在哪里了
    ?你能做一个plnkr或JSFIDLE吗?这对旧的ng repeat=“英雄中的英雄”有用吗。读这篇文章作为参考:谢谢丽莎,我会试试的。我还想到,*ngFor可能需要一个number属性才能工作。我的Heores类只有name的string属性。我的package.json和index.html没有为Angular 2和依赖项正确配置。现在很好用。谢谢莉萨!我懂了。当我切换到angular 2时,我会记住这一点。
    <h2>My favorite hero is {{ myHero }}</h2>
    
    <h2>My favorite hero is </h2>