<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body ng-app="myApp1"> <btn primary="true" lg block></btn> <script src="./js/Angular.js"></script> <script> var myApp1 = angular.module('myApp1', []); //第一个参数是指令的名字 第二个参数应该使用一个数组 //数组的最后一个元素是一个函数 myApp1.directive('btn', [function() { return { scope: { primary: '@', lg: '@', block: '@' }, //指令对象的属性 transclude: true, template: '<button class="btn{{primary?\'btn-primary\':\'\'}}">button</button>' } }]) </script> </body> </html>