我有一个使用AngularJS-UI(v0.14.3)的AngularJS(v1.4.7)指令。
在指令中,如果我只使用uib-tooltip
,我有一个可用的弹出窗口,例如:
...
directiveContent += '<span uib-popover="Some normal text">Popover!</span>';
...
一旦我将其切换到uib-tooltip-html
...
directiveContent += '<span uib-popover-html="Some <b>bold</b> text!">Popover!</span>';
...
出现的解析错误与指令的link:
部分有关,其中我观察指令的内容是否发生了变化,然后我重新编译内容:
scope.$watch('content', function(value) {
var span = angular.element(element.find('span')[1]);
span.html(value);
$compile(span)(scope); // <--- SOME ERROR OCCURS HERE
});
我编译以便将元素绑定到事件处理程序。
以下是具体的$parse
错误:
angular.js:12477 Error: [$parse:syntax] http://errors.angularjs.org/1.4.7/$parse/syntax?p0=%2F&p1=not%20a%20primary…expression&p2=14&p3=Some%20%3Cb%3Ebold%3C%2Fb%3E%20text!&p4=%2Fb%3E%20text!
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:6:416
at Object.s.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:209:339)
at Object.s.primary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:206:337)
at Object.s.unary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:503)
at Object.s.multiplicative (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:249)
at Object.s.additive (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:76)
at Object.s.relational (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:205:19)
at Object.s.equality (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:204:241)
at Object.s.logicalAND (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:204:94)
at Object.s.logicalOR (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:203:458)
at Object.s.ternary (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:203:253)
at Object.s.assignment (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:203:107) <span popover-append-to-body="true" popover-animation="true" uib-popover-html="Some <b>(anonymous function) @ angular.js:12477(anonymous function) @ angular.js:9246aa @ angular.js:8791K @ angular.js:8289g @ angular.js:7680g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684g @ angular.js:7684(anonymous function) @ angular.js:7555(anonymous function) @ my-directive.js:57n.$digest @ angular.js:15826n.$apply @ angular.js:16097h @ angular.js:10546K @ angular.js:10744e @ angular.js:10695E @ angular.js:10734e @ angular.js:5507(anonymous function) @ angular.js:5784
我怎么能解决这个问题?
答案 0 :(得分:2)
请参阅angular-ui-bootstrap repo上的this问题。使用tooltip / popover-html时推荐的方法是将内容用引号括起来:
'<span uib-popover-html="\'<span>Some <b>bold</b> text!</span>\'">Popover!</span>'
答案 1 :(得分:0)
我使用以下代码添加工具提示,也许它对您有用:
<inactive_icon></inactive_icon>
angular.element("inactive_icon")
.empty()
.replaceWith($compile('<i class="fa fa-minus-circle text-danger" tooltip-placement="right" uib-tooltip="File Inactive"></i>')($scope));