Joe
Joe

Reputation: 735

How do I show a string containing escape characters in AngularJS

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.

Upvotes: 0

Views: 5563

Answers (2)

Mike Lawson
Mike Lawson

Reputation: 735

Unfortunately, what you're asking for isn't possible. This would have to be fixed when scope.sites is created since it's currently providing you with malformed JSON.

Upvotes: 1

maque
maque

Reputation: 686

Just escape each special character with '\' so :

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

Upvotes: 1

Related Questions