question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document why some attribute directive are dash-case and some are camelCase

See original GitHub issue

Bug, feature request, or proposal:

Currently there is a confusion as to why mdInput is an attribute directive [which is the reason why it is written as mdInput instead of md-input] & md-button is a component

Since md-button(and other button variants) are used only as html attributes, it would be easy for the user’s mental model if he can write

<button mdButton> instead of <button md-button> similar to <input mdInput>

What is the expected behavior?

Ability to use button variations using camelCase such as <button mdButton>

What is the current behavior?

All button variations needs to be used using kabab cased attribute <button md-button>

What is the use-case or motivation for changing an existing behavior?

Now the user needs to know how button is implemented (which is why it is kabab case instead of camel), instead end user should not care how it is implemented, instead just knows elements follow kabab case & directives follow camelCase.

This way, the implementation detail does not leak to end user

The mental model of “html element => component”, “html attribute => directive” is easy to remember & intuitive for most angular developers.

Which versions of Angular, Material, OS, browsers are affected?

2.0.0-beta.2

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:12
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
jelbourncommented, May 9, 2018

The current behavior is that @Components are dash-case and @Directives are camelCase. The reasoning is that an element can only have one @Component, but multiple @Directive instances. So you can tell by looking at <button mat-button matTooltip="Hello"> that MatButton is the @Component, and all of the unprefixed attributes (disabled, color, disableRipple, etc.) apply to that, while MatTooltip is a directive and its properties would all be prefixed with matTooltip

1reaction
thw0rtedcommented, May 28, 2020

Just came from #18606. I think confusion arose there because the docs agree with @jelbourn, telling you to use camelCase directives, but the example for the same components shows the directives in dash-case (<mat-icon mat-list-icon>folder</mat-icon>).

Would it make sense to resolve this issue by reviewing the docs to ensure that both the Overview and Example tabs of each component consistently use these case conventions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should we use camelCase or dash-delimited in Angular.Js?
I am trying to create a new directive, the JS code goes as below: ... But back to the JS file, if you...
Read more >
How Angular knows that element <app-info> refers to the ...
Question How Angular knows that element <app-info> refers to the appInfo directive? Answer Every language has a style guide and a naming convention....
Read more >
Glossary | AngularDart Community Documentation
Learn about them in the Attribute Directives guide. ... In Angular documentation, “camelCase” always means lower camel case. ... dash-case.
Read more >
Setting attribute value of an element in camelCase using a ...
setAttribute it will lowercase the attribute name, before attaching to the element. When called on an HTML element in an HTML document, ...
Read more >
CamelCase vs underscores: Scientific showdown - whatheco.de
In the odd case that you are an experienced programmer who doesn't have a preference over using camel case or underscores for identifiers, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found