【发布时间】:2018-02-13 10:18:33
【问题描述】:
如何属性绑定子组件?我想通过其父组件将我的变量 high 变为 false or !this.high 但问题是,孩子正在循环
应用产品
<button class="ui primary small button"(click)="clearVals()">Clear Selected</button>
<app-product-list [dataSource]="data"></app-product-list>
@ViewChild(ProductListComponent) prodList: ProductListComponent;
clearVals() {
this.selectedOutsourced = this.selectedPrice = 0;
this.prodList.clear();
this.selectedArray = [];
}
应用产品列表
<div class="products-cards" *ngFor="let product of dataSource['docs']">
<app-product-card [product]="product"(highlightEvent)="highlight($event)">
</app-product-card>
</div>
@ViewChild(ProductCardComponent) prodCard: ProductCardComponent;
应用产品卡片
<div class="list card ui" (click)="highlight()" [class.selected]="high"> </div>
high : boolean = false;
highlight(){
this.high = !this.high;
}
这是育儿的顺序。最上层是从父到子
【问题讨论】:
-
“孩子被循环”是什么意思?
-
您是否尝试将事件从孩子传播到父母?
-
*ngFor @Carsten
-
@RahulSingh 实际上还有另一个父级,如果您单击该按钮,它将查看 app-product-list 组件
-
令人困惑的@Char
标签: angular boolean parent-child angular-components property-binding