angular * ngFor绑定到数组无法找到'object'类型的不同支持对象'[object Object]'

时间:2016-07-24 04:56:34

标签: angular angular2-template

我正在尝试编写单个组件来将数组呈现给模板。它应该是相当基础的。但我不确定为什么它会在RC.4中引发错误。

import {Component, AfterContentInit} from '@angular/core';
import {HeaderComponent} from "../common/shared/header/header.component";
import {SidenavComponent} from "../common/shared/sidenav/sidenav.component";

@Component({
    selector: 'home',
    templateUrl: 'app/home/home.component.html',
    providers: [],
    directives: [FORM_DIRECTIVES, CORE_DIRECTIVES, HeaderComponent, SidenavComponent],
    pipes: []
})
export class Home {
    names: Array<string>;

    constructor() {
      this.names = ["Alex Tuder",
            "Pedro Montoya",
            "Hal Jordan",
            "Tony Stark"];

    }
}

Html模板 -

<table class="table">
                                <thead>
                                    <tr>
                                        <th class="text-center">#</th>
                                        <th>Name</th>                                                                             
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr *ngFor="let name of names">
                                        <td> {{name}}</td>                                           
                                    </tr>    
                                </tbody>
                            </table>

的package.json -

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.2",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.4",
    "angular2-in-memory-web-api": "0.0.14",
    "bootstrap": "^3.3.6",
    "core-js": "^2.4.0",
    "jquery": "^3.1.0",
    "materialize-css": "^0.97.6",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.27",
    "zone.js": "^0.6.12"
  },
  "repository": {}
}

之前曾与其他时间合作过。但我不确定为什么会抛出错误。现在。

0 个答案:

没有答案