Error: [$compile:tplrt] 错误处理

第一次使用angularjs的directive指令,遇到非常气人的问题

 app.directive('hello', function() {

return {

restrict: 'E',

//        template: '<div>Hi there</div>',

templateUrl:'http://localhost:9090/keti/template/addKetiTemplate.html' ,

replace: true

};

});

/addKetiTemplate.html代码如下:

扫描二维码关注公众号,回复: 520207 查看本文章
<div>
    some stuff
</div>
<div>
    some other stuff
</div>

访问报错 Error: [$compile:tplrt] 

解决方法:
在两个div的外层添加一层div,如下
<div>
<div>
    some stuff
</div>
<div>
    some other stuff
</div>
</div>
然后就可以了
templateUrl引用的模板文件,需要一个根节点或者说根元素。不能出现并列的html元素代码,就比如两行div,等等。

猜你喜欢

转载自cyf-123456.iteye.com/blog/2269819