1
我有以下情形:角度编译的HTML不会调用函数的范围
HTML:
<span ng-if="model.thresholdText" compile="model.thresholdText"></span>
编译指示:
.directive('compile', ['$compile', function($compile) {
return function(scope, element, attrs) {
scope.$watch(
function(scope) {
return scope.$eval(attrs.compile);
},
function(value) {
element.html(value);
$compile(element.contents())(scope);
}
);
};
model.theresholdText
有时包含文本英语,有时在日本/西班牙/俄罗斯包括一些HTML。它总是在格式:
some text in origin language
<a href="" onclick="myFunc()">Origin language text</a>
Some more text in origin language
我会遇到以下问题:当产地语言是英文的,一切完美的作品和myFunc
被调用。然而,当文字是日语例如,我在控制台得到一个错误:
Uncaught ReferenceError: myFunc is not defined
你有没有考虑过使用ngBind而不是自定义指令? ngBind将填充html元素的内容。 –
我想你需要改变'onclick =“myFunc()”''ng-click =“myFunc()”' – aseferov
你说'myFunc'被调用并且工作完美,但是你又说'myFunc'没有定义。你可以显示'myFunc'代码吗? –