Reputation: 972
I define an object of type any in Typescript but when i build with ng build --prod --aot
it shows the property not exist auth_user
and auth_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))
}
i also tried
var payload:any = {
[environment.auth_password]:user.password,
[environment.auth_user] : user.username
}
but with no luck. Any solution will be appreciated.
Error detail
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; }'.
here is my complete service
@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))
}
}
Upvotes: 0
Views: 431
Reputation: 972
I had two file in the environment folder
environment.ts
and environment.prod.ts
And i was executing command ng build --prod --aot
so it was taking environment.prod.ts
while building
but in environment.prod.ts these properties were not defined since i never build for production after adding these property to environment.prod.ts It is working find
Upvotes: 1
Reputation:
Try the object's definition this way. Exchange '=' by ':'
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'
};
Upvotes: 0