Convert json & to & in AngularJS

前端 未结 2 1333
灰色年华
灰色年华 2021-01-20 16:00

I have an HTML element that have value attribute. The value should be Comfort & Protection but the name that comes from the JSON get result is Comfort &

相关标签:
2条回答
  • 2021-01-20 16:09

    Managed to solve the problem based on Max Zoom answer.

    I created a filter to filter ampersands, like this.

    app.filter('ampersand', function(){
        return function(input){
            return input ? input.replace(/&/, '&') : '';
        }
    });
    

    And on my View I changed from {{term.name}} to {{term.name | ampersand}}

    0 讨论(0)
  • 2021-01-20 16:18

    One option would be to replace the & string with & as below:

    var text = name.replace(/&/g, '&')
    
    0 讨论(0)
提交回复
热议问题