[英]Angular : Directive code not rendering the template
I simply cloned the angular seed project and added a directive as shown below: 我只是克隆了有角的种子项目并添加了一条指令,如下所示:
.directive('dataGrid',function(){
return{
restrict: 'E',
template : '<h1>HHHIII</h1>'
}
})
But when I use the directive <data-grid></data-grid>
the HTML content is not displayed. 但是,当我使用指令<data-grid></data-grid>
,不会显示HTML内容。 Can any one point out what I'm missing ? 任何人都可以指出我所缺少的吗?
And when I inspect the page in browser, here is what I see 当我在浏览器中检查页面时,这就是我看到的
<div ng-view="" class="ng-scope">
<data-grid class="ng-scope"></data-grid>
</div>
The problem is the name of the directive. 问题是指令的名称。 The prefix data-
is used for HTML5 custom attributes. 前缀data-
用于HTML5自定义属性。 Renaming your directive should solve the problem. 重命名您的指令应该可以解决问题。
data-
is reserved name. data-
是保留名称。 Angular ignores it by HTML5 standard. Angular通过HTML5标准将其忽略。 By prefixing dataGrid
with custom string it started working: 通过为dataGrid
加上自定义字符串作为前缀,它开始起作用:
app.directive('testDataGrid',function(){
return{
template: '<h1>HHHIII</h1>'
}
});
<test-data-grid></test-data-grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.