Try using the parseInt()
method to convert from string
to number
:
const idx: number = parseInt(params['id']);
console.log('por que string??? ' + typeof idx);
this.category = this._categoryService.getCategory( idx );
A <Type>
is called Type Assertation
. According to the documentation:
Type assertions are a way of telling the compiler "believe me,
I know what I'm doing. "A type assertion is like a type of
conversion in other languages, but does not perform any verification
special or data restructuring. It has no impact on time of
execution, and the compiler uses it exclusively. TypeScript assumes that
you, the programmer, have made the special controls that
you need
Which means that you do not necessarily cast it, but only provide more information about the type to cast.