zachsnow / ng-multi-transclude

ng-multi-transclude
MIT License
79 stars 19 forks source link

empty the element that is being transcluded #15

Closed littlemtravis closed 9 years ago

littlemtravis commented 9 years ago

call empty() on the element that is being transcluded.

This would allow me to have default content in the element, but allow the user to override the content.

//assume this is in a directive template named testDirective
<div ng-multi-transclude="footer">
   <div>This is text for the footer</div>
</div>

//implementation
<test-directive>
  <div name="footer">
    <div>Now this is the footer</div>
  </div>
</test-directive>

//Current - result
<test-directive>
  <div name="footer">
    <div>This is text for the footer</div>
    <div>Now this is the footer</div>
  </div>
</test-directive>

//Requested - result
<test-directive>
  <div name="footer">
    <div>Now this is the footer</div>
  </div>
</test-directive>
zachsnow commented 9 years ago

Yeah, this seems like a no-brainer, should have done this in the first place. What do you think about the idea of raising an error (or just a warning) if you don't pass a block for which there is no default? You could always pass an empty block. So:

<div class="container">
    <div ng-multi-transclude="required"></div>
    <div ng-multi-transclude="optional">Some default.</div>
</div>

And then this would work fine:

<div test-directive>
    <div name="required">Some thing.</div>
</div>

And this would raise an error about missing required:

<div test-directive>
    <div name="optional">Override the default.</div>
</div>

You could always just pass an empty block to signal your intention and avoid the error/warning:

<div test-directive>
    <div name="required"></div>
    <div name="optional">Override the default.</div>
</div>
littlemtravis commented 9 years ago

Zach,

I don't think an error is required. I have a template that I am allowing any section to be filled in, if nothing is set then it's just empty.

Thanks,

Sent from my phone.

Travis

On Dec 17, 2014, at 1:06 PM, Zach Snow notifications@github.com wrote:

Yeah, this seems like a no-brainer, should have done this in the first place. What do you think about the idea of raising an error (or just a warning) if you don't pass a block for which there is no default? You could always pass an empty block. So:

Some default.

And then this would work fine:

Some thing.

And this would raise an error about missing required:

Override the default.

You could always just pass an empty block to signal your intention and avoid the error/warning:

Override the default.

— Reply to this email directly or view it on GitHub.

zachsnow commented 9 years ago

I've added this and will make a new release. Cheers!