0
我有以下過濾器,似乎應該在我看來工作。當添加到指令中時,不會返回任何數據,就像數據中包含單引號一樣,就像「它是」一樣。角度過濾器取代單引號
angular.module('hcApp')
.filter('replace', function(){
return function(text) {
return text.replace(/'/g, '"');
};
});
我試圖逃避我的JSON數據,這是通過CMS來的單引號。這可能是與過濾器和指令已經存在的衝突嗎?
<div ng-bind-html="'{{over.contents}}' | to_trusted | replace "></div>
angular.module('hcApp')
.filter('to_trusted', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
過濾器是否正確地獲取輸入?嘗試將其打印到控制檯,例如。 '{{over.contents}}''在ng-bind-html裏面看起來不正確,因爲它需要一個表達式。您可以嘗試不使用「'和{{}}。 – Absor 2014-10-29 16:41:21