Angular2@input传递数组对象
在我的简单角度todo应用程序中有两个组件 todo-root.tsAngular2@input传递数组对象,angular,Angular,在我的简单角度todo应用程序中有两个组件 todo-root.ts import { Component } from '@angular/core'; export class TodoItem { todo: String; } @Component({ selector: 'todo-root', template: ` <div class="todo-root"> <todo-list [todoList]="todoTaskLi
import { Component } from '@angular/core';
export class TodoItem {
todo: String;
}
@Component({
selector: 'todo-root',
template: `
<div class="todo-root">
<todo-list [todoList]="todoTaskList"></todo-list>
<todo-add></todo-add>
</div>
`
})
export class TodoRootComponent {
todoTaskList= [
{todo: 'todo1'},
{todo: 'todo2'},
]
}
todo-list.ts
import { Component, Input, Output, EventEmitter } from '@angular/core';
export class TodoItem {
todo: String;
}
@Component({
selector: 'todo-list',
template: `
<div *ngFor="let todoTask of todoList">
<span>{{todoTask.todo}}</span>
</div>
`
})
export class TodoListComponent {
@Input()
todoList:TodoItem[] = [];
}
如何在todo列表组件ngFor循环中获取todoTaskList值。如何在这种情况下@input工作。有人能帮忙吗。更换这条线路
@Input() todoList:TodoItem[] = [];
与
为什么?您在构造函数中定义的内容没有效果,因为它将被输入更新覆盖。它应该可以正常工作,您可以创建一个plunker吗?
@Input() todoList:TodoItem[];