1
我只是玩角度指令,但不知何故评论添加指令的方式没有显示出来。这是标记。AngularJS指令作为评论
<!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>
指令定义
var app=angular.module('directive-app',[]);
app.directive("firstDirective", function() {
return {
restrict : "EACM",
templateUrl : 'template.html'
};
});
在template.html有一个h1元素。但是添加指令的注释方式并未在用户界面中显示出来,甚至在这种情况下还需要注释方法。
你可以给你一些解释。为什么替换只需要在注释 –
@MahtabAlam的情况下才需要首先,熟悉'replace'选项,请参阅https://stackoverflow.com/a/15286383/87972。当'replace'为'false'时,Angular会尝试将模板内容放入注释中,这就是为什么它不可见。当'replace'为'true'时,Angular会将模板内容替换为注释,这就是为什么它是可见的。 – Hoa
谢谢@Hoa –