Using Blaze.remove

Hey everyone.

I’m using Blaze.renderWithData to show a modal window like this:

<template name="fullStatModal">
  <div tabindex="-1" role="dialog" id="fullStatModal" class="modal fade">
      <button class="btn btn-default" data-dismiss="modal">Close</button>
  "click .officeFullStat": (event, template) ->
    Blaze.renderWithData Template.fullStatModal, @_id, document.body

So clicking “Close” hide modal but it is still in DOM and next time I click .officeFullStat one more #fullStatModal inserted to DOM.

According to docs I have to manually remove rendered view, but I have no idea how to do it. Now I just remove it with JQuery:


But I believe the instance of template with all subscriptions still in runtime.

I guess it should be somethink like this:

view = Blaze.renderWithData Template.fullStatModal, @_id, document.body

So let’s say I want to remove view when “Close” button of rendered template clocked. How can I achieve this?

Oh. Looks like I found solution.

Is it ok if I just delete template from itself?
  "click #closeFullStat": (event, template) ->
    Blaze.remove template.view

From your HTML it looks like you’re using Bootstrap. Take a look at how the leading bootstrap modal package (peppelg:bootstrap-3-modal) is doing this:

1 Like

Yes, already found it myself, thank you anyway.