<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<script src="js/angular.js"></script>
<title></title>
</head>
<body>

<div ng-controller="myCtrl">
</div>
<!--调用指令,并通过属性传参-->
<ts-directive ts-name="Hello World"></ts-directive>

<script>
var app = angular.module('myApp', ['ng']);
//创建指令
app.directive('tsDirective', function () {
return{
template:'<h1>{{tsName}}</h1>',
scope:{
tsName:'@'//@取ts-name属性对应的值
}
}
})

app.controller('myCtrl', function () {
console.log('myCtrl func is called');
})
</script>
</body>
</html>

相关文章:

  • 2021-11-28
  • 2021-09-17
  • 2021-11-28
  • 2021-11-28
  • 2021-10-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-01
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案