我有以下指令:
app.directive('renderPartial', function($compile) {
return {
restrict: "AE",
link: function(scope, element, attrs) {
var path = getPartial(attrs.module, attrs.file);
//path = /abc/some_file.html
scope[attrs.model] = path;
var el = $compile('<div ng-include="attrs.model"></div>')(scope);
element.html(el);
}
}
});
在我看来:
<render-partial module="abc" file="some_file" model="some_model"></render-partial>
现在由于某种原因,这不起作用,没有错误。但是文件没有被渲染。
答案 0 :(得分:1)
<强>更新强>
根据评论中附带的plunker: -
你需要做几件事
1)使用var el = $compile('<div ng-include="'+attrs.model+'"></div>')(scope);
2)element.append(el);
而不是平面HTML :-P
答案 1 :(得分:0)
你可以让它变得动态,如下:
myApp.directive('renderPartial', function($compile) {
return {
restrict: "AE",
link: function(scope, element, attrs) {
var path = 'test.html';
scope.path = path;
var el = $compile('<div ng-include="path"></div>')(scope);
element.append(el);
}
}
});