[英]Angular 5 Structural Directive
我正在嘗試創建一個可重用的搜索框組件,目前我的設置是這樣。
search.component.html
<div class="search-box-container">
<fa-icon class="search-icon" [icon]="faSearch"></fa-icon>
<input type="search" name="search" class="search-box" autocomplete="off" />
</div>
search.component.ts
import { Component, OnInit } from '@angular/core';
import { faSearch } from '@fortawesome/free-solid-svg-icons'
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.scss']
})
export class SearchComponent implements OnInit {
faSearch = faSearch;
constructor() { }
ngOnInit() {
}
}
我想跨多個組件使用它,如下所示:
<app-search [ngModel]="searchString" (onUpdate)="updateSearch"></app-search>
我的問題是如何訪問結構化組件內部主要組件中的父ngModel和onUpdate集。
根據@Stanisalv在評論中回答:
在主組件中,您只需使用
@Output
裝飾器將其綁定到搜索組件的公共屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.