1
all。 2つのコンポーネント間で文字列フォーマットを送信する際の問題。双方向データ結合文字列の角度2エラー
私はFILTERNAME
<as-filters-panel [(filterName)]="filterNameField" [(selectedSort)]="sortByField"></as-filters-panel>
を取得しようとする子どもたちのコンポーネントの親コンポーネントで
フィルタ-panel.component.ts
`@Component({
selector: 'as-filters-panel',
templateUrl: './filters-panel.component.html',
styleUrls: ['./filters-panel.component.css']
})
export class FiltersPanelComponent implements OnInit, AfterContentInit {
filterByName:string;
@Output() searchNameChange = new EventEmitter<string>();
categories : Category[];
subscribe : Subscription;
constructor(public categoryService : CategoryService, public router : Router) {
}
@Input() get filterName() {
console.log(this.filterByName);
return this.filterByName;
}
set filterName(val) {
this.filterByName = val;
this.searchNameChange.emit(this.filterByName);
}
onNameChange(model: any) {
this.filterName = model;
}`
とHTMLテンプレート
<input class="filterInput" type="text" [ngModel]="filterName" (ngModelChange)= "onNameChange($event)">
を作成
を作成し、filterNameFieldを作成します:string = ''; .tsファイル 文字列では機能しませんが、番号を送信しようとするとうまく動作します。
なぜイベントを明示的にトリガーしたいのですか?ngModelChange ??あなたの期待は何ですか? – Aravind
私は入力フィールドからデータを受け取りたい、テキスト値が必要 –
あなたのコンポーネントの入力フィールドはどこですか? – Aravind