Angular 4 - 在 *ngfor 创建动态组件后绑定 jQuery 事件(点击)
Angular 4 - Bind jQuery event (click) after *ngfor created dynamic components
我的 viewasd 中有以下代码
<div class="item" *ngFor="let property of propertiesRecent; let i=index">
<app-property [property]="property" (propertyCreated)="onPropertyCreated()"></app-property></div>
现在 app-属性 看起来像这样:
<span class="col-lg-2 socialShare">
<fa name="share-alt" size="3"></fa>
</span>
我想在上面绑定一个 jquery 事件,但是在 propertiesRecent 的值更新后 DOM 更新后,我松开 jquery 单击事件监听器..
$('.socialShareIcons').hide()
我该怎么做?如果您检查我尝试自定义事件的 ngFor,我在 app-属性 组件中尝试了 AfterViewChecked 但没有帮助...
有类似的问题,这是 github 上的 link 提供的解决方案和相应的讨论
简而言之:
<div #label *ngFor="...
Component:
Class SuperComponent {
ViewChild('label')
public label: any;
...
ngAfterViewInit() {
this.handleEndOfNgfor();
this.label.changes.subscribe(()=>this.handleEndOfNgfor());
}
private handleEndOfNgfor()
console.log('hooray!');
}
}
我的 viewasd 中有以下代码
<div class="item" *ngFor="let property of propertiesRecent; let i=index">
<app-property [property]="property" (propertyCreated)="onPropertyCreated()"></app-property></div>
现在 app-属性 看起来像这样:
<span class="col-lg-2 socialShare">
<fa name="share-alt" size="3"></fa>
</span>
我想在上面绑定一个 jquery 事件,但是在 propertiesRecent 的值更新后 DOM 更新后,我松开 jquery 单击事件监听器..
$('.socialShareIcons').hide()
我该怎么做?如果您检查我尝试自定义事件的 ngFor,我在 app-属性 组件中尝试了 AfterViewChecked 但没有帮助...
有类似的问题,这是 github 上的 link 提供的解决方案和相应的讨论
简而言之:
<div #label *ngFor="...
Component:
Class SuperComponent {
ViewChild('label')
public label: any;
...
ngAfterViewInit() {
this.handleEndOfNgfor();
this.label.changes.subscribe(()=>this.handleEndOfNgfor());
}
private handleEndOfNgfor()
console.log('hooray!');
}
}