Reputation: 4733
I'm getting that error:
Property 'module' does not exist on type 'Menu'.
Property 'parentId' does not exist on type 'Menu'.
and code looks like this:
private menus: Menu[];
for (var i = 0; i < this.menus.length; i++) {
if ((this.currRoute == "/" + this.ls.actLan + this.menus[i].module) && this.menus[i].parentId !== 0) {
this.IsActive.emit(this.menus[i].parentId);
} else {
this.IsActive.emit(0);
}
}
BUT I have imported that ts file
import { Menu } from './menu';
and there I have these properties
export class Menu {
constructor(
id: number,
type: number,
module: any,
urlType: string,
url: string,
name: string,
parentId: any
) { }
}
what could be wrong?
Upvotes: 1
Views: 2524
Reputation: 40554
You actually don't have any properties on Menu
class. You can automatically create properties from constructor arguments. See parameter properties:
export class Menu {
constructor(
public id: number,
public type: number,
public module: any,
public urlType: string,
public url: string,
public name: string,
public parentId: any
) { }
}
Now all the parameters will also be public properties of Menu
.
Or if you don't want to use parameter properties, you can define them one by one like this:
export class Menu {
id: number;
// ...
constructor(id: number, type: number, module: any, url: string, name: string, parentId: any) {
this.id = id;
// ...
}
}
Upvotes: 3
Reputation: 222552
Change it like this,
export class Menu {
id: number;
type: number;
module: any;
urlType: string;
url: string;
name: string;
parentId: any;
constructor(id: number, type: number, module: any, url: string, name: string, parentId: any) {
this.id = id;
this.module = module;
this.type = type;
this.url = url;
this.name = name;
this.parentId = parentId;
}
}
Upvotes: 0