助けてください。親コンポーネント内のボタンをクリックすると、親コンポーネント内の子コンポーネントをロードしようとしていました。ボタンのクリックで子コンポーネントを読み込む方法4
提案が必要です。私はちょうどそれを働かせましたが、私は本当にそれを行うための適切な方法であることを知りたいです。実装は次のとおりです。
<div class="btn-group" role="group">
<button type="button" id="stars" class="btn btn-primary" data-toggle="tab" (click)="clickStars()"><span class="glyphicon glyphicon-star" aria-hidden="true"></span>
<div class="hidden-xs">Stars</div>
</button>
</div>
<div class="btn-group" role="group">
<button type="button" id="favorites" class="btn btn-default" data-toggle="tab" (click)="clickFavorite()"><span class="glyphicon glyphicon-heart" aria-hidden="true"></span>
<div class="hidden-xs">Favorites</div>
</button>
</div>
<div class="btn-group" role="group">
<button type="button" id="following" class="btn btn-default" data-toggle="tab" (click) = "clickFollowings()"><span class="glyphicon glyphicon-user" aria-hidden="true"></span>
<div class="hidden-xs">Following</div>
</button>
</div>
</div>
<div class="well">
<div class="tab-content">
<app-stars *ngIf="!starsHidden"></app-stars>
<app-favorites *ngIf="!favoriteHidden"></app-favorites>
<app-followings *ngIf="!followingsHidden"></app-followings>
</div>
</div>
</div>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-profile',
templateUrl: './profile.component.html',
styleUrls: ['./profile.component.css']
})
export class ProfileComponent implements OnInit {
starsHidden:boolean;
favoriteHidden:boolean;
followingsHidden:boolean
constructor() { }
ngOnInit() {
this.starsHidden = false;
this.favoriteHidden = true;
this.followingsHidden = true;
}
clickStars(){
this.starsHidden = false;
this.favoriteHidden = true;
this.followingsHidden = true;
}
clickFavorite(){
this.starsHidden = true;
this.favoriteHidden = false;
this.followingsHidden = true;
}
clickFollowings(){
this.starsHidden = true;
this.favoriteHidden = true;
this.followingsHidden = false;
}
}
ようこそ。このサイトはコード作成サービスではなく、完全なソリューションを提供するためのものではありません。ユーザーは、途中で特定のプログラミング問題を解決するのに役立つために、ここにいくつかの努力とコードを示すことが期待されます。もう何か試しましたか?お読みください:https://stackoverflow.com/help/asking –
コードレビューについては、こちらからお問い合わせください。https://codereview.stackexchange.com/ –