组件类型角度指令 ng 模板
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>
。
请帮助我!!
正如@emil.c所指出的。您的代码中有拼写错误:
templateUrl: "my-info-msg.html"
当您从template1Url
中删除"1"时,它工作正常。
https://plnkr.co/edit/Q20v7zSHHVPNJOOievrm?p=preview
template1Url
中有一个错别字,删除 template
和 Url
之间的1
,你应该没问题。
相关文章:
- 从ng模板访问作用域
- 包含ng模板的指令中的角度transclude(通用Confirm Modal)
- AngularJS路由在初次点击时没有加载ng模板
- 无法在 ng 重复中显示 ng 模板
- 未为text/ng模板计算角度表达式
- ng模板,带有ui.router,单独的文件
- 未加载内联HTML ng模板
- ng模型绑定无法使用ng模板
- 组件类型角度指令 ng 模板
- ng模板内联,但仍尝试加载
- 动态创建 ng 模板以使用 angular-ui-bootstrap 显示弹出框内容
- 具有模态的ng模板内的角度指令
- ng模板作为空字符串添加到$templateCache
- Aurelia有ng模板替代品吗
- ''访问受限URI被拒绝'"尝试使用ng模板时出错
- 为什么我的ng模板没有在angularJS中显示$scope和ng的值
- 在带有text/ng模板的script标记中使用ng控制器
- 在Angular/Django SPA中存放ng模板的最佳位置是什么?
- ng单击脚本类型ng模板不起作用
- 无法直接访问ng模板内的范围变量