附上前端测试页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>angular</title>
<script src="/static/angular/angular.js-1.7.6/angular.min.js"></script>
</head>
<body ng-app="myApp">
<!--M:代表注释型的显示值,必须在restrict中申明为M-->
<!-- directive: runoob-directive -->
<!--值得注意的是,如果要开启把自定义指令注释来显示值,那么需要加上repalce,选择为true-->
<!--<P>hello world !</p> template中在你输入的内容外面必须要加一个标签,不管啥标签,不然不能显示值-->
<script>
var app = angular.module("myApp", []);
app.directive("runoobDirective", function() {
return {
restrict : "M",
replace : true,
template : "<P>hello world !</p>"
};
});
</script>
</body>
</html>
附上控制台Elements元素的打印效果