2012-09-14 6 views
15

Zrobiłem filtr, aby dodać antyklasę po wartości, jeśli inna podana wartość nie jest pusta i chciałbym oddzielić ten tekst od pozostałej części z  . W rzeczywistości sam filtr działa, ale w prawo ciąg " " jak na stronie.Angular js - Zwraca łańcuch znaków ze znacznikami HTML, takimi jak  

angular.module('ngMod', []). 
filter('antislash', function() { 
    return function(input) { 
    if(input==null || input.length === 0){ 
     return null; 
    }else{ 
     return ' / '; 
    } 
    } 
}); 

Wyświetlane na stronie:  / 

istnieje odpowiednik filtra html lub coś?

Odpowiedz

42

Działa, podając wartość unicode dla  .

angular.module('ngMod', []). 
filter('antislash', function() { 
    return function(input) { 
    if(input==null || input.length === 0){ 
     return null; 
    }else{ 
     return '\u00A0/\u00A0'; 
    } 
    } 
}); 

Można również użyć $sanitize z ng-bind-html i ng-bind-html-unsafe do snipets HTML.