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'代碼嗎? –