简体   繁体   中英

Have to click 2 times before it opens my component

GM, I am a beginner in Angular, i use Leaflet for my application. I created some markers, and i want to open another component when i click on the marker.

This is the marker click

marker.on('click', () => {
  this.isAnySelectedObject = true;
});

Then in the app.js, under the map div, i put a ngIf on my child component

<marker-infos *ngIf="isAnySelectedObject"></marker-infos>

I have to click 2 times before the component appears, can someone help me please?

put this code in ngOnInit():

marker.on('click', () => {
  this.isAnySelectedObject = true;
});

The solution is:

import the ChangeDetectorRef and everytime i call a component in my map i only have to call this function "this.changeDetector.detectChanges();"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM