【问题标题】:why row is not render in angular 2?为什么行不以角度 2 呈现?
【发布时间】:2017-01-19 10:54:55
【问题描述】:

我正在尝试使用input attr 将数据从一个组件发送到另一个组件。 但我收到此错误

VM575 zone.js@0.6.17?main=browser:484 Unhandled Promise rejection: Template parse errors:
Can't bind to 't' since it isn't a known property of 'row-item'.
1. If 'row-item' is an Angular component and it has 't' input, then verify that it is part of this module.
2. If 'row-item' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message.
 ("          <ul>
                 <li *ngFor="let tt of todoService.todos">
                <row-item [ERROR ->][t]='tt'></row-item>
                  </li>

我在演示中添加了这个

import {Component, Input} from "@angular/core";
@Component({
  selector:'row-item',
  template :`<div>
 <span>{{t}}</span>
</div>`
})
export class TodoRow{
  @Input t;
}

这样使用

@Component({
    selector: 'todo-list',
    template: `<div>
                <ul>
                 <li *ngFor="let tt of todoService.todos">
                <row-item [t]='tt'></row-item>
                  </li>
                    </ul>
                   </div>`
})

这是我的代码 http://plnkr.co/edit/WXgdKF2gx9Kpj7eqmDJv?p=preview

【问题讨论】:

    标签: angularjs angular angular2-routing


    【解决方案1】:

    你的声明应该是这样的:

    @Input() t;
    

    【讨论】:

    • @Input('t') t;
    【解决方案2】:

    在为组件定义输入时忘记添加 ()。

    import {Input} from '@angular/core';
    
    Input() t;
    

    您应该在为组件提供输入时尝试提供基本名称:

    @Input('t') t;
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多