私は、テーブル項目としてグループ項目をリストするリストコンポーネントを持っています。リンクの1つは、ユーザーがアイテムを編集できるようにすることです。編集項目は別のコンポーネントです。ユーザーが編集をクリックすると、既存のデータを編集コンポーネントに渡す必要があります。どうやってやるの?ここコンポーネント間のデータを角4で渡します。
は、成分が(同じアプリである以外)階層によって関連付けられていない場合、私のリストコンポーネントここ
<div class='table-responsive'>
<table class='table' *ngIf='groups && groups.length'>
<thead>
<tr>
<th>Avatar Image</th>
<th>Display Name</th>
<th>Description</th>
<th>Member Count</th>
<th>Total Post</th>
<th>Last Modify Date</th>
<th></th>
</tr>
</thead>
<tr *ngFor='let group of groups | groupFilter:listFilter'>
<td><img [src]='group.group_avatar_image' class="img-responsive" style="max-height: 50px;"></td>
<td><a [href]='group.url'>{{group.display_name}}</a></td>
<td>{{group.description}}</td>
<td>{{group.total_members_count}}</td>
<td>{{group.total_posts}}</td>
<td>{{group.updated_at | date: 'dd/MM/yyyy'}}</td>
<td><a href="#" [routerLink]="['/Edit Group']">Edit</a></td>
</tr>
</table>
</div>
私のリストコンポーネント
import { Component, OnInit,Input } from '@angular/core';
import { Group } from '../groupModel';
import { GroupsService } from '../groups.service';
@Component ({
selector: 'groups-lst',
moduleId: module.id,
templateUrl: 'groups-list.component.html'
//styleUrls: ['groups.component.css']
})
export class GroupsList implements OnInit{
constructor(private _groupsService: GroupsService) {}
title: string = 'Groups List';
listFilter: string = '';
errorMessage: string;
groups: Group[];
ngOnInit():void{
this._groupsService.getGroups()
.subscribe (group => this.groups = group,
error => this.errorMessage = <any>error);
}
}