Skip to content

feat(common): introduce ngAttr directive - #13958

Closed
DzmitryShylovich wants to merge 3 commits into
angular:masterfrom
DzmitryShylovich:gh/13940
Closed

DzmitryShylovich wants to merge 3 commits into
angular:masterfrom
DzmitryShylovich:gh/13940

Conversation

@DzmitryShylovich

Copy link
Copy Markdown
Contributor

Closes #13940

@pkozlowski-opensource pkozlowski-opensource added the area: common Issues related to APIs in the @angular/common package label Jan 17, 2017
@pkozlowski-opensource

Copy link
Copy Markdown
Member

@DzmitryShylovich you've forgotten to commit unit tests :-)

Before doing more work on this I would like to hear a bit more about real-life scenarios, though.

@DzmitryShylovich

Copy link
Copy Markdown
Contributor Author

Before doing more work on this I would like to hear a bit more about real-life scenarios, though.

I have doubts too, this is why I didn't add tests :)

@mhevery

mhevery commented Jan 28, 2017

Copy link
Copy Markdown
Contributor

What happens if you have:

<div [foo]="exp1" [ngAttr="{ foo: exp2 }">

There is no easy way to detect that.

I would also like to see real world scenarios. Please update or close this PR

@DzmitryShylovich

DzmitryShylovich commented Jan 28, 2017 •

Copy link
Copy Markdown
Contributor Author

@mhevery

I would also like to see real world scenarios

Take a look at #13940 (comment)

@pkozlowski-opensource

Copy link
Copy Markdown
Member

@DzmitryShylovich @mhevery I've updated the original issue with my thoughts on the ngAttr: #13940 (comment)

tl;dr; is that IMO it is not adding enough benefit to "pay" for itself. Having said this I would prefer that @mhevery decides here.

@mhevery

mhevery commented Jan 31, 2017

Copy link
Copy Markdown
Contributor

My experience tells me that more things means more bugs and supporting voes. So I vote against this as well. Going to close the PR for now.

@nayfin

nayfin commented Sep 8, 2018

Copy link
Copy Markdown

I am working on a form generator that takes a JSON configuration, built by consumer of library, and automatically builds out a form in Angular Material. I would like to allow user to pass custom attributes to each form field to suit there needs e.g. aria labels, flex-layout directives, etc... [ngAttr]="config.attrs" would be very useful. I am currently try to use elementRefs and viewChild but I am having some trouble getting it to behave as expected.

A feature like this seems more useful for code that builds code, but if the performance will take a big hit then I need to find another solution. My library is available here, and corresponding code is in the DynamicFormModule. I'll update if I find a good workaround.

Update
I got the custom attributes to show up in DOM by accessing a @ViewChild inside of an ngAfterViewInit and using Renderer2.setAttribute , but the flex-layout directives don't seem to have any effect. It seems like afterViewInit is happening after flex-layout does it's thing. Even if this did work, I am forced to use NativeElement when using this method, which warned against in documentation. Maybe the Ivy update will address these issues, maybe it won't.

I just wanted to make sure I voiced this as it is a good use case for the feature. Especially as users become better versed with angular and start building more generative code.

@nayfin

nayfin commented Sep 8, 2018

Copy link
Copy Markdown

@DzmitryShylovich would you be amicable to me pulling your attrs code into a module in an open source library? If so, I would like to stick with the ngAttrs naming convention. This way if it ever it ever is implemented in @angular/core, consumers of the library can easily convert to the native method. I can add some testing as well.

@GregKass

GregKass commented Oct 2, 2018 •

Copy link
Copy Markdown

+1 to @nayfin, for basically the same reason. Also building JSON configurable form from reusable base components.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: common Issues related to APIs in the @angular/common package cla: yes state: blocked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ngAttr like ngClass and ngStyle

6 participants