-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($compile): support multi-elements in all declaration styles #3379
Conversation
@rodyhaddad - Thanks for this PR. I like that you have obviously read the commit guidelines and you have even added in the new error message docs. Do you have a specific use case for this feature, which cannot be achieved with attributes? I seem to remember there was some reason for only allowing attribute directives. I know that comment-based directives are inherently difficult and @IgorMinar spent a long time fighting with Internet Explorer to get a comment based repeater working to no avail. So I suspect that this is not a goer. If you do want to push this PR forward then make sure that your tests exercise the full functionality correctly on Internet Explorer 8. |
PR Checklist (Minor Feature)
|
Can you make sure you have signed the CLA too. Thanks |
I've signed the CLA (Rodric Haddad)
Everything can be achieved with just attributes. Also, I find this: <table>
<!-- directive: ng-repeat-start item in list -->
<tr>
<td>I get repeated</td>
</tr>
<tr>
<td>I also get repeated</td>
</tr>
<!-- ng-repeat-end -->
</table> A lot more elegant that this: <table>
<tr ng-repeat-start="item in list">
<td>I get repeated</td>
</tr>
<tr ng-repeat-end>
<td>I also get repeated</td>
</tr>
</table> The last
The only PRs I found that address this similar issue are the following
As a side-note, |
I have just finished adding tests for my changes, and everything seems to pass in IE8 |
I've built on the work of angular#2783 to make multi-elements possible in all directive decralation styles. Basically angular#2783 was limited to directives declared via attributes. With this commit, appending X-start and X-end would work in Comments, Attributes, ClassNames and ElementNames ```html <table> <!-- directive: ng-repeat-start item in list --> <tr>If ngRepeat's 'restrict' get changed to include 'M'</tr> <tr>I get repeated</tr> <!-- ng-repeat-end --> </table> ```
the comment based stuff doesn't work in certain elements in IE (e.g. inside I appreciate all the work you put into this, but I think that it unnecessarily complicates things. Sometimes giving people more options to do the same thing is not beneficial. I'm going to close this PR for now. If you have a use-case that can't be implemented using the current attribute-based multi-element directive please post it here and reopen the PR. thanks again! |
This PR doesn't complicate things, it makes things more consistent. Angular supports directives declared in 4 styles ( As a developer, I would expect I can't think of a use-case where multi-node directives declared as comments/classNames/elementsNames can do the job and attributes couldn't, but comment-based repeaters are a lot nicer to work with: <div class="row header">
...
</div>
<div ng-repeat-start="item in list" class="row">
<div class="span3">
{{ item }}
</div>
<div class="span9">
{{ item }}
</div>
</div>
<div ng-repeat-end class="row">
<div class="span9">
{{ item }}
</div>
<div class="span3">
{{ item }}
</div>
</div>
<div class="row footer">
...
</div> Having the <div class="row header">
...
</div>
<!-- directive: ng-repeat-start item in list -->
<div class="row">
<div class="span3">
{{ item }}
</div>
<div class="span9">
{{ item }}
</div>
</div>
<div class="row">
<div class="span9">
{{ item }}
</div>
<div class="span3">
{{ item }}
</div>
</div>
<!-- ng-repeat-end -->
<div class="row footer">
...
</div> I don't know about you, but the second one seems a lot easier to read. The no comments in This PR doesn't change anything with that, it just makes comment based directives more useful :)
The other issue with comment based multi-node directives is using them in conjunction with omitted tags (e.g. I still think this would be useful to many. ...I don't see a button to open back the PR. If you want me to add to the docs the things I've talked about above, and then merge, you can open up the PR again for me to add new |
I've built on the work of #2783 to make multi-elements possible in all
directive decralation styles.
Basically #2783 was limited to directives declared via attributes.
With this commit, appending X-start and X-end would work
in Comments, Attributes, ClassNames and ElementNames
I will be adding tests for the compileSpec very soon, just wanted to know if it looks good for you guys.
After I write the tests, I also want to add
restrict: 'CMA'
for the following directives: