下面是我的html代码片段:
<div ng-controller="ctrl">
<custom-tag
title = "name"
body = "content">
</custom-tag>
</div>
下面是编写的控制器和指令:
var mod = angular.module("main_module",[]);
//Controller
mod.controller("ctrl",function($scope) {
$scope.name="Page Title";
$scope.content="sample_template.html";
});
//Directive
mod.directive("customTag", function() {
return {
'restrict' : 'E',
'scope' : {
'title' : '=',
'body : '='
},
'templateUrl' : 'directive_template.html'
};
});<!-- directive_template.html -->
<div>
<div>{{title}}</div>
<div ng-include="'{{body}}'"></div>
</div>
指令呈现的实际html如下:
<div>
<div ng-binding></div>
<!-- ngInclude: '{{body}}' -->
</div>
显然,它没有从<custom_tag>中的属性中获取指令作用域变量
请告诉我为什么会发生这种情况,以及我如何解决这个问题。谢谢
发布于 2016-09-09 03:06:52
检查控制台中的错误,额外的引号和{{}}个大括号破坏了东西。
<div>
<div>{{title}}</div>
<div ng-include="body"></div>
</div>
http://plnkr.co/edit/G9JfIJGhSghUbgkKLXnV?p=preview
https://stackoverflow.com/questions/39397036
复制相似问题