這是我的html頁面:爲什麼這個指令不起作用..有人可以解釋嗎?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="angular.min.js"></script>
<script src="scoping_directives.js"></script>
</head>
<body ng-app="scoping">
<div ng-controller="OuterController">
<p>{{outer_var}}</p>
<my-directive></my-directive>
</div>
</body>
</html>
這裏是JS文件:
angular.module('scoping', [])
.controller('OuterController', function($scope){
$scope.outer_var = 10;
})
.directive('myDirective', function() {
console.log("inside directive1");
return {
/*scope :{
inner_var : 20
},*/
template:'<p>tanmay</p>'
};
});
有人可以解釋爲什麼在指令模板不會被渲染。我只得到10作爲輸出。輸出所產生的錯誤並不存在。
指令默認限制爲屬性。請參閱$ compile文檔:https://docs.angularjs.org/api/ng/service/$compile – Sacho 2014-10-27 05:17:27
並且您正在使用您的指令作爲元素。換言之,限制:'E'是必需的 – 2014-10-27 05:20:16
在鏈接上我找到了這個: EACM子集的字符串,它將指令限制爲特定的指令聲明樣式。如果省略,則使用默認值(元素和屬性)。 ë - 元素名稱(默認):<我的指令性>我-指令> A - 屬性(默認):
Ç - 類: 米 - 評論:<! - 指令:MY-指令exp - > – JackSparrow 2014-10-27 05:39:28