Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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 localizerouter在发布后不更改语言_Angular - Fatal编程技术网

Angular localizerouter在发布后不更改语言

Angular localizerouter在发布后不更改语言,angular,Angular,我正在使用这个组件,我有这个代码 import { Component } from '@angular/core'; import {LocalizeRouterService} from 'localize-router'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppCo

我正在使用这个组件,我有这个代码

import { Component } from '@angular/core';
import {LocalizeRouterService} from 'localize-router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app works!';

  constructor(private localize: LocalizeRouterService) {}

  changeLanguage(lang: string) {
    this.localize.changeLanguage(lang);
  }
}
和html格式

<button (click)="changeLanguage('en')">EN</button>
<button (click)="changeLanguage('de')">DE</button>
这在localhost中运行良好,但当我使用ng build-prod和IIS中的主机发布它时,它会记录此错误:

JSON中位置0处出现意外标记<


怎么了?

应用程序正在尝试从本地化路由器加载JSON配置文件。我猜您忘了将其添加到angular-cli.json中的资产数组中。由于您的Web服务器设置为使用index.html文件为任何404请求提供服务,因此应用程序正在尝试将html文件解析为json,这将导致典型错误:

JSON中位置0处出现意外标记<


令牌在node_modules/localize router folder@gsiradze中找不到任何config.json,这是您自己制作的配置文件,也可能是你忘了添加到资产中的字典文件我更新了我的答案好吧,但我在生成产品时出错了:enoint:没有这样的文件或目录,stat'C:\Users\…\webstorprojects\loca我应该在代码中添加ILocalizeRouteConfig接口吗?这很奇怪,它已经在你的资产文件夹中了,所以它应该会起作用。无需将其添加到您的配置中
{
  ...
  "apps": [
    {
      ...
      "assets": [
        ...,
        "path/to/localize-router/config.json"
      ],
    }
  ]
}