Mahtab Alam
Mahtab Alam

Reputation: 1870

AngularJS Directive as a comment

I'm just playing with angular directives, but somehow the comment way to add directives is not showing up. Here is the markup.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="angular.js"></script>
</head>

    <body ng-app="directive-app">

         <first-directive></first-directive>

         <div first-directive></div> 

         <div class=first-directive></div> 

         <!-- directive: first-directive -->     

         <script src="main.js"></script> 


</body>
</html>

Directive definition

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

app.directive("firstDirective", function() {
    return {
        restrict : "EACM",  
        templateUrl : 'template.html'
    };
});

In template.html there is one h1 element. But comment way to add directives is not showing up in UI and in which case comment approach is even required.

Upvotes: 2

Views: 2404

Answers (1)

Hoa
Hoa

Reputation: 3207

Set replace option to true as follows

app.directive("firstDirective", function() {
  return {
    restrict: "EACM",
    replace: true,
    templateUrl: 'template.html'
  };
});

Here's demo.

Upvotes: 5

Related Questions