js代码:
var app = angular.module("myApp", []);
app.directive("clock", function() {
return {
restrict: 'E',
scope: {
timezone: "@"
},
template: "<div>12:00pm {{timezone}}</div>"
}
});
app.directive("panel", function() {
return {
restrict: 'E',
transclude: true,
scope: {
title: "@"
},
template: "<div style='border:3px solid #000000><div class='button'>{{title}}</div><div ng-transclude></div></div>"
}
});
Html代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<title></title>
</head>
<body>
<div ng-app="myApp">
<clock timezone="MST"></clock>
<br /><br /><br />
<panel title="I am a title" >
<clock timezone="PST"></clock>
</panel>
</div>
<script type="text/javascript" src="../js/angular.min.js" ></script>
<script type="text/javascript" src="../js/components.js" ></script>
</body>
</html>
效果:
12:00pm MST
<div button'="" class="ng-binding" style="box-sizing: border-box;">I am a title
12:00pm PST