perotom perotom - 2 months ago 6
TypeScript Question

Angular 2 class doesn´t get recognised

I tried to use this class:

class SortExpression {

constructor(field, asc) {
this.field = field;
this.asc = asc;

field: string;
asc: boolean;

toQueryString() {
return (this.asc ? '+' : '-') + this.field;

in my component like that:

this.sortFields = new SortExpression('name', true);

and i get an
Uncaught (in promise): ReferenceError: SortExpression is not defined
exception and i really donĀ“t know why. I am pretty new to angular 2 so maybe i am missing something really simple?


You have to export your class in order to be imported.

export class SortExpression {