Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  112] [ 4]  / answers: 1 / hits: 29931  / 8 Years ago, tue, february 9, 2016, 12:00:00

It looks like there is no replace option in new AngularJS 1.5 Component concept (like it was for directives).



What would you suggest if I want to have table row <TR> element as component? Is it not possible in terms of valid HTML?



Real example: mailBox component has mail components inside. By markup mail-box-component is table, and mail-box is tr.



<mail-box>
<mail ng-repeat=mail in $ctrl.mails mail=mail></mail>
<mail-box>





UPD: related discussion about directives - Why is replace deprecated in AngularJS?


More From » angularjs

 Answers
88

This is not possible the-angular-way anymore since the replace: true flag has been deprecated



Why is replace deprecated in AngularJS?



the replace: true flag had come up with more problems than solutions which is why it was removed.
therefore you can not build directives in such a way anymore and provide valid table-tr-td markup.



However, there are two reasons why this is not as bad as it looks:




  1. you can do everything you want to do without table, tr, td, etc.
    just using elements like div, span, etc. and some css on it


  2. web-components (and directives were a first attempt to simulate
    them) are not meant to represent such small fragments of the markup.
    they are more thought of as a fully functional component actually
    doing something. so whatever you want to do with your tr that you
    think it's worth building an element-directive around it, it
    probably isnt.




Maybe, what you can do is using an attribute-directive instead:



<tr my-mail-directive></tr>


and your my-mail-directive does the magic on the tr element


[#63382] Sunday, February 7, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yaquelina

Total Points: 517
Total Questions: 101
Total Answers: 96

Location: Egypt
Member since Tue, Jul 6, 2021
3 Years ago
yaquelina questions
;