저는 2 각도를 시도하고 있습니다. 이해할 수없는 이상한 문제에 직면하고 있습니다. 각도 2 ng 첫 번째 상황이 정의되지 않았습니다.
나는 간단한 할 일 목록을 만들어 내 응용 프로그램을 실행할 때이 오류 메시지가 :반복를 선두가 정의되지 않은 이유를 이해가 안가. 내 배열이 하드 코드되어 있으므로 왜이 문제가 있는지 알 수 없습니다. 여기 이 응용 프로그램의 코드이다
가
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { TodoNavComponent } from './app.todo-nav';
import { TodoListComponent } from './app.todo-list';
import { TodoComponent } from './app.todo';
@NgModule({
imports: [ BrowserModule ],
declarations: [ TodoNavComponent, TodoListComponent, TodoComponent ],
bootstrap: [ TodoNavComponent, TodoListComponent, TodoComponent ]
})
export class AppModule { }
app.todo-list.ts
을import { Component } from "@angular/core";
import { TodoService } from "./app.service";
@Component({
selector: "todo-list",
template: `
<div class="container">
<ul class="list-group">
<todo *ngFor="let todo of todos" [todo]="todo"></todo>
</ul>
</div>`,
providers: [TodoService]
})
export class TodoListComponent {
todos: any[] = [
{ name: "Do shopping", done: false },
{ name: "Get some gaz for my car", done: true },
{ name: "Download last season of Game of Thrones", done: false }
];
constructor(private service: TodoService) {
service.todoAdded$.subscribe(
todo => {
this.todos.push(todo);
}
);
service.todoRemoved$.subscribe(
todo => {
this.todos = this.todos.filter(
(value, index, array) => {
return todo.name !== value.name;
}
);
}
);
}
}
app.todo.ts app.module.ts
import { Component, OnDestroy, Input } from "@angular/core";
import { TodoService } from "./app.service";
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: "todo",
template: `
<li class="list-group-item">
<i class="pull-right glyphicon glyphicon-remove" (click)="remove()"></i>
{{todo.name}}
</li>`,
providers: [TodoService]
})
export class TodoComponent implements OnDestroy {
@Input() todo;
subscription: Subscription;
constructor(private service: TodoService){
this.subscription = service.todoAdded$.subscribe(
todo => {
this.todo = todo;
}
);
}
remove() {
this.service.removeTodo(this.todo);
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
다음은 렌더링입니다.
내가 무엇을 놓쳤을까요? 첫 번째 발생이 아닌 다른 발생이 발생하는 이유가 무엇인지 이해할 수 없습니다.
감사합니다.
에이 수정을 원하는 경우 .name을 u를 도움이 될 것입니다 : HTTP : // 유래.com/questions/40291111/angle-2-first-item-in-array-missing-using-ngfor –