Thank you for any help, I understand this may be a newby question... but I can't see what I am missing and I have no compilation problems in my TypeScript.
I'm trying to do something quite simple, I want to have a variable that tells me which of my Main Menu Items is selected.
So I binded my HTML with several variables like this: (if you know how I could bind an enum value directly I will appreciate that).
<div id ="menu_popular" class="{{menuClass}}" style=" left:90px; top:368px;">
Menu Item
</div>
Then I want to update my code declarations by invoking a function selectMenu like this:
import {Component} from '@angular/core';
import {MainMenuItem} from './domain';
@Component ({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent
{
title = 'Angular App';
menuClass = 'div.menu_text';
}
let selectedItem: any = MainMenuItem.POPULAR;
const selectMenu = function (item: MainMenuItem) {
console.log ('Switching Selected Menu from: ' + selectedItem + ' to: ' + item);
selectedItem = item;
console.log('Asigned');
console.log(this.AppComponent.menuClass);
if (item === MainMenuItem.YEIIIII)
{
...
selectMenu (MainMenuItem.YEIIIII);
But I will send me a runtime error stating Cannot read property 'AppComponent' of undefined
It seems I can't reach the AppComponent values any way I
console.log(this.AppComponent.menuClass);
or
console.log(this.menuClass);
What am I doing wrong :(
Thanks!
console.log(this.AppComponent.menuClass);This doesn't work because you dont have direct access to the component instance. You want to write this type of code from within the Class .