I am new to Angular2 and Typescript. I am trying to gain access to a @Input from the constructor in my class. A service is called from inside the constructor and I need to pass it an argument.
@Component({
selector:'side-menu',
templateUrl:'menu.html',
providers: [MenuService]
})
export class SideMenuComponent {
@Input() blockType;
menuItems
constructor(menuService:MenuService){
this.menuItems = menuService.getMenuItems(this.blockType); // Sends Undefined
this.menuItems = menuService.getMenuItems('HardCodedString'); //This works
}
}
and this is my Service
@Injectable()
export class MenuService {
getMenuItems(type) {
console.log(type)
switch(type){
case 'Thing':
return [];
break;
case 'Otherthing':
return [];
break;
default:
return [];
}
}
}
How can I ensure the @Input gets sent to the service?