2

I simply cloned the angular seed project and added a directive as shown below:

    .directive('dataGrid',function(){
    return{
        restrict: 'E',
        template : '<h1>HHHIII</h1>'
    }
})

But when I use the directive <data-grid></data-grid> the HTML content is not displayed. Can any one point out what I'm missing ?

And when I inspect the page in browser, here is what I see

<div ng-view="" class="ng-scope">
  <data-grid class="ng-scope"></data-grid>
</div>
3
  • try adding replace: true Commented Feb 28, 2016 at 17:58
  • check if directive is added to main module - angular won't report errors for unknown directives Commented Feb 28, 2016 at 18:03
  • OK I see you added directive inside ng-view, thats the problem, put directive usage inside one of the views that is rendered eg. view1 Commented Feb 28, 2016 at 18:06

2 Answers 2

4

The problem is the name of the directive. The prefix data- is used for HTML5 custom attributes. Renaming your directive should solve the problem.

Sign up to request clarification or add additional context in comments.

Comments

0

data- is reserved name. Angular ignores it by HTML5 standard. By prefixing dataGrid with custom string it started working:

app.directive('testDataGrid',function(){
  return{
      template: '<h1>HHHIII</h1>'
  }
});

<test-data-grid></test-data-grid>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.