ngFor繰り返しコンポーネントのラジオボタンの範囲は、私は1つのポストである二つの成分を持っている何の孤立
ではありません:
import {Component} from '@angular/core';
@Component({
selector: 'post',
template: `
<h1>{{title}}</h1>
<p>{{postText}}</p>
<ul>
<li *ngFor="let postData of posts">
<news-feed></news-feed>
</li>
</ul>
`
})
export class Post {
title : string;
postText : string;
posts = [{title:"Post1",postText:"Wow greate post"}, {title:"Post1",postText:"Wow greate post"}]
constructor(title:string, postText:string) {
this.title = title;
this.postText = postText;
}
}
他のニュースフィードです:
import {Component} from '@angular/core';
@Component({
selector: 'news-feed',
template: `
<h1>News Feed</h1>
<div class="radios">
<div class="form-check form-check-inline">
<label class="form-check-label">
<input class="form-check-input" type="radio" value="success" [(ngModel)]="commandResult.type (change)="getCommandResult()"> Succeeded
</label>
</div>
<div class="form-check form-check-inline">
<label class="form-check-label">
<input class="form-check-input" type="radio" value="fail [(ngModel)]="commandResult.type (change)="getCommandResult()"> Failed
</label>
</div>
</div>`
})
export class NewsFeed {
commandResult: any = {
type: 'fail'
};
constructor() {
}
getCommandResult() {}
}
Iポストコンポーネント内のニュースフィードコンポーネントを繰り返しています。 ver繰り返しコンポーネントのいずれかのラジオボタンを変更します。繰り返しコンポーネントすべてが変更されることがわかります。おそらく、私はang2を初めて使ったので、間違った方法でこれに近づいています。どんな助けもありがとうございます。親コンポーネントクラスでIn this link, I think I am facing similar issue, I know its angular1 but still the same issue.
あなたは親子コンポーネントの相互作用について学ぶ必要があるいくつかの読書。角度のあるドキュメントは素晴らしいソースです – Vega
@Vegaここで私が間違っていることについて考えていただけますか?私はドキュメントを見て、私は関連する情報を見つけることができませんでした。 –