Jeremy Gillick
Jeremy Gillick

Reputation: 2700

EmberJS - didInsertElement for previously displayed view

I have a flow with multiple pages and when I use 'transitionTo' to go back to a route/view that has already been displayed, it's 'didInsertElement' method is not called. (it was fired the first time the view was displayed, though)

Is there an event that my view can hook into that will be called every time it is displayed?

My routes look something like this

App.Router.map(function() {
    this.resource("parent", { path: "/parent" }, function() {
        this.resource("child", { path: "/child" });
    });
});

So when I'm in the child view and call:

this.transitionTo('parent')

The parent view does not fire 'didInsertElement'.

Upvotes: 1

Views: 470

Answers (3)

Jeremy Gillick
Jeremy Gillick

Reputation: 2700

I found that I can use setupController in the routes to let me know each time the route is rendered. I know it's not the best solution, but so far, it is the most reliable.

Upvotes: 1

raytiley
raytiley

Reputation: 684

If your routes are nested your templates should be too. So I would expect your template to look something like this:

<script type="text/x-handlebars" data-template-name="parent">
  <!-- Your parent View stuff -->

  {{outlet}} <!-- This is where your child gets rendered
</script>

So your parent view stuff is already inserted and stays inserted. It shouldn't be going anywhere when you transition into / out of the parent.

What exactly are you trying to do that you need the didInsertElement after transitioning back to the parent. The didInsertElement hook is really for lower level dom manipulation, like setting up jQuery plugins. If your trying to do more application logic stuff it probably belongs somewhere else.

Upvotes: 0

Dan McClain
Dan McClain

Reputation: 11920

The parent is already rendered, as the child is rendered inside of the outlet in the parent. What are you trying to do when you transition back to the parent view? There might be a better way to do what you want

Upvotes: 0

Related Questions