简体   繁体   中英

Why is the HTML-Code not rendered when I use a custom angularjs directive

HTML:

<section>
     <!-- <div ng-controller="Ctrl"> -->
     <div nt-attr-dir></div>
</section>

script.js

angular.module('docsSimpleDirective', [])
  .directive('ntAttrDir', function factory() {
    var directiveDefinitionObject = {
      template: "<div> Test </div>",
      replace:false,
      restrict:"A"
    };
    return directiveDefinitionObject;
  });

So expected result is the html-code should look like

<section>
 <!-- <div ng-controller="Ctrl"> -->
     <div nt-attr-dir><div> Test </div></div>
</section>

But it looks always as below

<section>
 <!-- <div ng-controller="Ctrl"> -->
     <div nt-attr-dir></div>
</section>

What am I missing so that Test is not being displayed.

The only thing I can think of is the ng-app directive missing:

<html ng-app="docsSimpleDirective">

Why?

  • This directive is 100% valid.
  • I Assume there is no hidden error in the console which wasn't reported.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM