简体   繁体   English

AngularJS指令作为注释

[英]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. 在template.html中,有一个h1元素。 But comment way to add directives is not showing up in UI and in which case comment approach is even required. 但是,添加指令的注释方法未在UI中显示,在这种情况下,甚至需要注释方法。

Set replace option to true as follows replace选项设置为true ,如下所示

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

Here's demo . 这是演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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