angularJs 指令的用法

<!DOCTYPE html>
<html ng-app='app'>
<!--
A attribute属性:当做属性来使用
<div xingoo></div>
  E element元素:当做标签元素来使用
<xingoo></xingoo>
  C class类:当做CSS样式来使用
<div class="xingoo"></div>
  M comments注释:当做注释使用(这种方式在1.2版本下亲测不可用!)
-->
<head>
<meta charset="utf-8">
<title translate="TITLE">Basic usage</title>
<style>body { text-align: center; }</style>
</head>

<body ng-controller="ctrl">
<hello></hello>
<label>{{name}}</label>
<input type="text" set-Focus="">
<script type="text/javascript" src="../script/angular.js"></script>
<script type="text/javascript">
var myApp = angular.module('app',[]);
myApp.controller('ctrl', ['$scope', function($scope) {
$scope.name = "姓名";
}]);
myApp.directive('setFocus', function(){
return {
restrict: 'A',//A 表示attribute属性
link: function(scope, element){
element[0].focus();
}
};

});
myApp.directive('hello', function() {
return {
restrict: 'E', //E 表示 element元素
template: '<div>Hi there</div>',
replace: true
};
});
</script>

</body>
</html>

 

posted @ 2016-02-26 15:23  流星小子  阅读(139)  评论(0编辑  收藏  举报