IT
[angular] retrieve the data as number
로바아토
2018. 3. 21. 11:43
this code looks like no problem. but actually it could be error.
this.route.params.subscribe(
(params:Params) => {
this.server = this.serversService.getServer(params['id']);
}
);
let's look at this method. >> getServer(id:number)
the parameter of getserver is for 'number'
but the data from route.params is always string. so it makes the error.
we can fix this with just one typing of '+'
'+' cast the variable from string to number.
this.route.params.subscribe(
(params:Params) => {
this.server = this.serversService.getServer(+params['id']);
}
);