Why the didInsertElement of a component got executed when the page just got loaded?


In my template code, I put my component in a if block like this:

{{#if result}]

And in the didInsertElement method of MyPostComponent, I want to do some DOM manipulations. But When I entered this page, the console reported that can’t find the target DOM, meanwhile the result is false instead of true. Then I tried put a console.log(‘in didInsertElement’) in the didInsertElement and refreshed the page, and I saw ‘in didInsertElement’ in the console but my-post component is not there in the page! So why did didInsertElement get executed without my component inserted into the page right after the page is loaded? Thank you


I found my mistake. I put the if inside my component :frowning: