4

I need to call the class method through console which intern accesses the class variable and then it reflects on the HTML. I Referred Call a service function from browser console in angular 6 but I was unable to access this keyword.

export class AppComponent {
    title = 'calender-app';
    timeslot: any =  [];

    constructor(){
      window['plotEvent'] = this.plotEvent;
    }
  
    plotEvent(events: Calender[]): void{
    // not able to access this.timeslot when I call it from browser's console.
    this.timeslot.push(...events); // getting error as can't read property timeslot of undefined.
    }
1
  • Show us what you have tried. The link you have posted should work. Commented Jul 21, 2020 at 6:14

1 Answer 1

4

I assume that you are trying to access a typescript method on the browsers console.

You can make the entire angular component.ts's variables, methods etc. available to access in the browser console by adding OnInit or in the constructor the following:

Let's say you are trying to access a method within the AppComponent, you go.

OnInit() {
    window['AppComponent'] = this;
}

Or:

constructor() {
    window['AppComponent'] = this;
}

The same works in services too.

Then in the console you go: AppComponent.myMethod()

Sign up to request clarification or add additional context in comments.

3 Comments

This updated the timeslot but the HTML did not reflect the changes.
I don't think that you can refresh the dom with new content. once it was loaded by accessing the console.
You can try in OnInit to call this.plot(events) to see the HTML changes

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.