gpt4 book ai didi

angularjs - 我们可以在 $compile 中使用 ng-transclude 吗?

转载 作者:行者123 更新时间:2023-12-03 07:55:26 24 4
gpt4 key购买 nike

我们能否在指令中编译 ng-transclude 如下所述。我收到错误:

[ngTransclude:orphan] Illegal use of ngTransclude directive in the template! No parent directive that requires a transclusion found. Element:

我的代码:

ngApp.directive("floater", ['$compile', function($compile) { 
return {
restrict: "E",
replace: true,
transclude: true,
require: 'nuTitle',
scope: {
nuTitle: "=",
onMinimize: "&"
},
template: "<div></div>",
link: function(scope, element, attrs) {
var template = "<div class='floater'>" +
"<div class='content'>" +
...
"<div class='clearfix' ng-transclude></div>" +
...
"</div>" +
"</div>";
templateObj = $compile(template)(scope);
element.append(templateObj);
}
};
}]);

最佳答案

问题类似于this

一种可能的解决方案是更改这些行:

template: "<div ng-transclude></div>",
compile: function compile ( element, attrs) {
var template = "<div><div>"+element.html()+"</div></div>";

element.html(template);
}

http://jsfiddle.net/qbt0rsek/2/

这样就避免了错误

关于angularjs - 我们可以在 $compile 中使用 ng-transclude 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27036046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com