首页 > 解决方案 > 如何将此字符串转换为模板文字

问题描述

我想将下面的字符串转换为模板文字。谁能帮我

 public readonly defaultSvgIcon:string = "<svg aria-hidden=\"true\" focusable=\"false\""+
"data-prefix=\"fas\" data-icon=\"external-link-alt\" class=\"svg-inline--fa fa-external-link-alt fa-w-16\""+
  "role=\"img\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 512 512\"><path fill=\"currentColor\""+
    "d=\"M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z\">"+
  "</path></svg>"

我尝试了下面的代码,但它抛出错误:

"<svg aria-hidden=`true` focusable=`false`"+
"data-prefix=`fas` data-icon=`external-link-alt` class=`svg-inline--fa fa-external-link-alt fa-w-16`"+
  "role=`img` xmlns=`http://www.w3.org/2000/svg` viewBox=`0 0 512 512`><path fill=`currentColor`"+
    "d=`M432,320H400a16,16,0,0,0-16,16V448H64V128H208a16,16,0,0,0,16-16V80a16,16,0,0,0-16-16H48A48,48,0,0,0,0,112V464a48,48,0,0,0,48,48H400a48,48,0,0,0,48-48V336A16,16,0,0,0,432,320ZM488,0h-128c-21.37,0-32.05,25.91-17,41l35.73,35.73L135,320.37a24,24,0,0,0,0,34L157.67,377a24,24,0,0,0,34,0L435.28,133.32,471,169c15,15,41,4.5,41-17V24A24,24,0,0,0,488,0Z`>"+
  "</path></svg>"

标签: angulartypescript

解决方案


用这个

 public readonly defaultSvgIcon:string = `your whole svg code lines without escaping esacaping special character`

推荐阅读