Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度7:从后端添加路由链接_Angular_Typescript_Ionic Framework_Angular7_Ionic4 - Fatal编程技术网

Angular 角度7:从后端添加路由链接

Angular 角度7:从后端添加路由链接,angular,typescript,ionic-framework,angular7,ionic4,Angular,Typescript,Ionic Framework,Angular7,Ionic4,我试图找到一种方法,将路由链接添加到从后端API检索的数据中。 我尝试在后端数据中添加…,然后使用bypassSecurityTrustHtml(),但它不起作用 我想知道我是否必须使用.html子模板,或者是否可以从TypeScript完全管理它 编辑1: 下面是我从后面收到的数据: { "status":"OK", "result":{ "chmn":[ { "id":267, "number":"",

我试图找到一种方法,将路由链接添加到从后端API检索的数据中。 我尝试在后端数据中添加
,然后使用
bypassSecurityTrustHtml()
,但它不起作用

我想知道我是否必须使用.html子模板,或者是否可以从TypeScript完全管理它

编辑1: 下面是我从后面收到的数据:

{
   "status":"OK",
   "result":{
      "chmn":[
         {
            "id":267,
            "number":"",
            "hanzi":"\u4e00",
            "simplified":"",
            "mnemonics":"one; <a>\u58f1<\/a> <a>\u7532<\/a>; <a>\u4f96<\/a> <a>\u4fde<\/a> <a>\ud842\udf9b<\/a> <a>\u4ee4<\/a> <a>\u5f10<\/a> <a>\u6b66<\/a> <a>\u6238<\/a> <a>\u81f3<\/a> <a>\u767e<\/a>;",
            "alike":"",
            "mine":false,
            "meaning":"",
            "reference":"",
            "remnant":false
         }
      ]
   }
}
在模板中:

<span *ngFor="let mnemonic of kanji.mnemonics">
    <span *ngIf="mnemonic.length > 1" [innerHTML]="mnemonic | sanitizeHtml"></span>
    <a *ngIf="mnemonic.length == 1" routerLink="/details/{{mnemonic}}">{{mnemonic}}</a>
</span>

{{助记符}}

您不能拥有
\u58f1
\u4f96
。。。作为Url参数(尚未)。 尝试在对象结构中发送动态路由链接,例如:

routes: { link: string, text: string }[] = [
    {
      link: "login", // a valid url string
      text: "\u58f1" // a renderable "CJK UNIFIED IDEOGRAPH" sign
    },
    {
      link: "home",
      text: "\u4f96"
    }
  ]
然后可以动态渲染路由,例如:

<div *ngFor="let route of routes">
  <a routerLinkActive="active" 
    routerLink="/{{route.link}}">{{route.text}}</a>
</div>


从后端接收整个锚定选项卡(如
\u58f1
)是个坏主意。我从您的响应片段u58f1中了解到的是一个id/代码。您只需从后端获取这些id,然后像这样使用它
如果可能的话。

尝试从后端发送对象数据。您能否共享一些代码,以便我们更好地了解您想要实现什么以及什么不起作用?我在第一篇文章中添加了一个示例。
<div *ngFor="let route of routes">
  <a routerLinkActive="active" 
    routerLink="/{{route.link}}">{{route.text}}</a>
</div>