toddmotto / angularjs-styleguide

AngularJS styleguide for teams
https://ultimateangular.com
5.96k stars 700 forks source link

Suggestion of best practise #123

Closed ptitgraig closed 8 years ago

ptitgraig commented 8 years ago

Hello. I suggest the following best practise regarding component:

Avoid component attribute name starting with data- as AngularJS eats the "data-" string

<!-- my-component.html -->
<my-component data-src="$ctrl.dataSrc"></my-component>
// my-component.js
...
bindings : {
  dataSrc: '<'
}

This code does above not work because the binding should be:

// my-component.js
...
bindings : {
  src: '<'
}

This is source of confusion. One should avoid attribute starting with data-

AkosLukacs commented 8 years ago

True, it's part of a documented normalization step for attribute names: https://docs.angularjs.org/api/ng/type/$compile.directive.Attributes#!

On Thu, 6 Oct 2016 at 13:18 Grégory Pelletey notifications@github.com wrote:

Hello. I suggest the following best practise regarding component:

Avoid component attribute name starting with data- as AngularJS eats the "data-" string

// my-component.js... bindings : { dataSrc: '<' }

This code does above not work because the binding should be:

// my-component.js... bindings : { src: '<' }

This is source of confusion. One should avoid attribute starting with data-

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/toddmotto/angular-styleguide/issues/123, or mute the thread https://github.com/notifications/unsubscribe-auth/AAziK4eAdXMQ0xeIm3lJYKJiot145Qm-ks5qxNkBgaJpZM4KP00I .

toddmotto commented 8 years ago

I think this is just one of those things that you'd know if you were using data-* attributes, I don't feel it's styleguide worthy IMO.