不同语言的 Angular 编译 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

在服务器的 html 中使用 onclick 而不是 ng-click。

最新更新