限制你的指令只能通过特定的方式来调用

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title></title>

<link rel="stylesheet" href="">

</head>

<body ng-app="myApp">

<div runoob-directive></div>

</body>

<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>

<script>

var app = angular.module("myApp",[]);

app.directive("runoobDirective",function(){

return {

restrict:"A",

template:"<h2>只能通过属性的方式来调用</h2>"

}

});

</script>

</html>

说明:

restrict 值可以是以下几种:

  • E 作为元素名使用

  • A 作为属性使用

  • C 作为类名使用

  • M 作为注释使用

限制你的指令只能通过特定的方式来调用