How do I show a string containing escape characters in AngularJS

时间:2015-05-24 21:45:02

标签: html angularjs html-escape-characters

I have a UNC file path stored in a structure

scope.sites = [
    {
        id: 1,
        nickname: 'Development',
        sitepath: '\\SERVERA.mydomain.com\sites\panoply\wwwroot',
        active: true
    }
];

I want to display the sitepath in the tooltip, as such:

<label style="width:100%;font-size:10px;" title="{{target.sitepath}}">
    {{target.nickname}}
</label>

But as backslashes are escape characters what I get is \SERVERA.mydomain.comsitespanoplywwwroot.

I thought I could use {{target.sitepath.replace('\\', '\\\\')}} or {{target.sitepath.replace('\', '\\')}}.

But neither of those seem to work.

2 个答案:

答案 0 :(得分:1)

Just escape each special character with '\' so :

 scope.sites = [
                {
                    id: 1,
                    nickname: 'Development',
                    sitepath: '\\\\SERVERA.mydomain.com\\sites\\panoply\\wwwroot',
                    active: true
                }

答案 1 :(得分:1)

不幸的是,你要求的东西是不可能的。当创建scope.sites时,必须修复此问题,因为它正在为您提供格式错误的JSON。