[英]Component type angular directive ng-template
在下面的代碼中,
<!DOCTYPE html>
<html>
<head>
.....
</head>
<body ng-app="app">
<script type="text/ng-template" id="my-info-msg.html">
<strong>{{o.msg}}</strong>
</script>
<div ng-controller="emp as o">
<div my-info-msg>
</div>
</div>
</body>
</html>
var app = angular.module("app", []);
function MyController(){
this.msg= 'This is a message';
}
app.controller('emp', MyController);
function MsgDirective(){
return{
template1Url: "my-info-msg.html"
};
}
app.directive('myInfoMsg', MsgDirective);
自定義指令my-info-msg
不會在<div my-info-msg> </div>
添加模板<strong>{{o.msg}}</strong>
<div my-info-msg> </div>
。
請幫我!!!
正如@ emil.c指出的那樣。 您的代碼中有拼寫錯誤:
templateUrl: "my-info-msg.html"
從template1Url
刪除“1”時,它可以正常工作。
在template1Url
有一個拼寫錯誤,刪除template
和Url
之間的1
,你應該沒問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.