11

What is the recommended practice for labelling Angular directives?

Other than html validation, are there any other benefits to prefixing both the in-built and my own custom directives with "data-"?

Or is it unnecessary clutter?

Brett Postin
  • 11,215
  • 10
  • 60
  • 95

2 Answers2

9

I would say data- would be best practice. Since this will allow the html to validate, it should be a standard practice for developers. It may cause a bit of clutter, but overall I think it helps maintain the intergrity of the app and of the developer. And seeing as it doesn't matter to angular that I can tell thus far, then there really is no reason not to use data-.

selanac82
  • 2,920
  • 4
  • 27
  • 37
0

You can use data-ng-, instead of ng-, if you want to make your page HTML valid.
This wont give error

<div ng-app="">

<p>Input something in the input box:</p>
<p>Name: <input type="text" ng-model="name"></p>
<p ng-bind="name"></p>

</div>

This will give error

<div data-ng-app="scope" data-ng-init="name='test'"

<p>Input something in the input box:</p>
<p>Name: <input type="text" data-ng-model="name"></p>
<p data-ng-bind="name"></p>

</div>
Vahap Gencdal
  • 1,900
  • 18
  • 17