0
list-profile html docの中で提供されているリンクを一度押して変数を送信します。現在のコードは機能せず、クラッシュします。必要に応じて詳細を提供することができます。routerLinkを介して新しいコンポーネントにパラメータを渡します。
リスト-profile.component.html
<div class="col col-sm-4 col-sm-offset-4">
<ul id="list_of_users">
<li class="list-group-item list-group-item-action" *ngFor="let user of users"><a [routerLink]="['/profile', user.id]" routerLinkActive="active" (click)="testFunc(user.id)">{{user.name}}</a></li>
</ul>
</div>
app.module.ts
const appRoutes: Routes = [
{ path: 'addProfile', component: AddProfileComponent },
{ path: 'listProfiles', component: ListProfilesComponent},
{ path: 'profile:id', component: ProfileComponent}
];
それはもうクラッシュしません!しかし、どこで変数を取得するのですか?コンストラクタの中に? – Amar
コンストラクタまたはngOnInit内部 –
コード例を提供できますか?なぜなら、コンポーネント 'atm'は、 'ProfileComponent'クラスが 'OnInit'インターフェースを正しく実装していないからです。プロパティ 'ngOnInit'のタイプは実装できません。型 '(id:string)=> void'は型 '()=> voidの代入不可能です。 – Amar