ng 构建错误 属性 未找到

ng build error with property not found

我在 Typescript 中定义了一个类型为 any 的对象,但是当我使用 ng build --prod --aot 构建时,它显示 属性 不存在 auth_userauth_password

export const environment = {
  production: false,
  api_url: 'http://localhost:8033',
  token_name: 'X-Auth-Token',
  auth_user: 'X-Auth-Username',
  auth_password: 'X-Auth-Password'
};

authenticate(user: User) {
    var payload:{[x: string]: any} = {}
    payload[environment.auth_user] = user.username;
    payload[environment.auth_password] = user.password;
    return this.apiService.post("/authenticate", {}, new Headers(payload))
}

我也试过

var payload:any = {
      [environment.auth_password]:user.password,
      [environment.auth_user] : user.username
    }

但运气不好。 任何解决方案将不胜感激。

错误详情

ERROR in /home/vikram/code/angular/start/src/app/user/services/user.service.ts (26,20): Property 'auth_password' does not exist on type '{ production: boolean; api_url: string; }'.
ERROR in /home/vikram/code/angular/start/src/app/user/services/user.service.ts (27,20): Property 'auth_user' does not exist on type '{ production: boolean; api_url: string; }'.

这是我的完整服务

@Injectable()
export class UserService implements OnInit {


  constructor(private apiService: ApiService, private jwtService: JwtService) {
  }

  ngOnInit() {

  }
  saveUser(user: User): Observable<any> {
    return this.apiService.post("/user", user);
  }
  authenticate(user: User) {
    var payload:any = {
      [environment.auth_password]:user.password,
      [environment.auth_user] : user.username
    }
    return this.apiService.post("/authenticate", {}, new Headers(payload))
  }
}

以这种方式尝试对象的定义。将“=”替换为“:”

export const environment: {
  production: false,
  api_url: 'http://localhost:8033',
  token_name: 'X-Auth-Token',
  auth_user: 'X-Auth-Username',
  auth_password: 'X-Auth-Password'
};

我在环境文件夹中有两个文件 environment.tsenvironment.prod.ts

我正在执行命令ng build --prod --aot

所以在建造

时需要 environment.prod.ts

但在 environment.prod.ts 中,这些属性未定义,因为我在将这些 属性 添加到 environment.prod.ts 后从未构建生产环境 它正在工作 find