【发布时间】:2016-04-05 02:57:59
【问题描述】:
我正在学习角度,所以在阅读文章时,有时会卡住以理解输出。这里我混淆了渲染 html 输出。
代码取自http://www.w3schools.com/angular/tryit.asp?filename=try_ng_directive
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" w3-test-directive></div>
<script>
var app = angular.module("myApp", []);
app.directive("w3TestDirective", function() {
return {
template : "I was made in a directive constructor!"
};
});
</script>
</body>
</html>
上面的代码运行后输出如下
<div w3-test-directive="" ng-app="myApp" class="ng-scope">I was made in a directive constructor!</div>
我的问题是为什么指令的模板文本会被添加到开始和结束 div 标记中?`
为什么这个属性是空白的w3-test-directive="" in div ?
此文本 I was made in a directive constructor! 可能已添加到 w3-test-directive 的属性中,因此 html 输出可能如下所示
<div w3-test-directive="I was made in a directive constructor!" ng-app="myApp" class="ng-scope"></div>
请帮助我理解为什么指令的模板文本会被添加到开始和结束 div 标记中?` 谢谢
【问题讨论】:
-
你希望它被添加到哪里?
标签: angularjs