angularjs:如何处理与弹出一个指令,这样数据来自控制器模型 [英] angularjs: how to handle a popup with a directive so that data comes from controller model
问题描述
假设我有一个模板URL这个标签,被注射到HTML从模型来(HTML基本上<立GT;要点):
Suppose I have this tag in a template URL, into which HTML coming from the model is injected (HTML is basically <li> bullet points):
<div ng-bind-html="accident.description.impact"></div>
模式的一部分如下:
A portion of the model is as follows:
"cause":
"<ul>\n\
<li>\n\
<div><span inline-popover \n\
popover-html=\"Taper pour ouvrir la vue détaillée\" \n\
popover-placement=\"bottom\" \n\
popover-label=\"Larve de taupin\">Larve de taupin</span></div>\n\
</li>\n\
<li>Semences en cours de germination</li>\n\
</ul>",
正如你可以看到,一些与LT;李&GT;包含标签,使打开一个弹出。
And as you can see, some <li> contains tags that enables for opening a popup.
我有问题,是跨度是从他的属性切断,一旦局部注射。
The issue I have, is that the span is cut off from his attributes, once injected in the partial.
任何想法?
推荐答案
这里的问题是: NG-绑定-HTML
不只是输出变量的内容。你所需要的是一个组件,即 $编译
的code,使更多的指令工作。
The problem here is: the ng-bind-html
does simply output the content of the variable. What you need here is a component, that $compiles
the code, to make additional directives work.
<div ng-compile-html="accident.description.impact"></div>
使用Javascript:
Javascript:
directives.directive("ngCompileHtml", function ($http, $compile)
{
return {
restrict: "A",
scope: {
"ngCompileHtml": "="
},
link: function (scope, element)
{
var template = angular.element(scope.ngCompileHtml);
$compile(template.contents())(scope);
$(element).append(template);
}
};
});
这篇关于angularjs:如何处理与弹出一个指令,这样数据来自控制器模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!