UltraSonja
UltraSonja

Reputation: 891

Divs and AngularJS

I find myself using a lot of divs when programming with AngularJS. Is this normal, or is there a better way of using Angular directives without divs? I believe that excessive use of div tags makes the HTML ugly, hard to read, and lacking in semantics.

Upvotes: 0

Views: 35

Answers (1)

sjm
sjm

Reputation: 5468

If you wanting your Markup to be more semantic and readable from a programmers point of view and you wish to encapsulate some reusable functionality then Directives will help as something like:

var app = angular.module('myapp', []);

app.directive('helloWorld', function() {
   return {
  restrict: 'AE',
  replace: 'true',
  template: '<div><h1>My Title</h1><div>Hello World!!</div></div>'
   };
});

Can be included in your HTML as:

<hello-world><hello-world>

But the Rendered HTML will still be the divs, otherwise it maybe of more benefit to try to include more HTML5 semantic tags found here: http://www.w3schools.com/html/html5_semantic_elements.asp

Upvotes: 1

Related Questions