Angular shows error of past file version but the error is actually resolved

Viewed 49

I have a method getMonths() and I wanted to add an argument year to it. The method is only used in one place:

<div *ngFor="let month of getMonths()" class="calendar-table">
...
</div>

If I add the argument to the method getMonths(year) and change the code above to call getMonths(selectedYear) angular gives me the following error:

    ERROR in src/app/user-calendar/user-calendar.component.ts:108:27 - error TS2554: Expected 1 arguments, but got 0.

    108     for(let month of this.getMonths()) {
                                  ~~~~~~~~~~~

      src/app/user-calendar/user-calendar.component.ts:35:13
        35   getMonths(year) {
                       ~~~~
        An argument for 'year' was not provided.

Notice, that angular seems to use the previous version of my template, where selectedYear is not provided. I tried to kill ng serve and run it again, I also tried to run ng build --prod but the error remains.

Unlike in the error message the template looks like this:

<div *ngFor="let month of getMonths(selectedYear)" class="calendar-table">
...
</div>
1 Answers

I've never seen the practice of iterating over the value returned from a function so I checked out this reference - *ngFor using a function, returns a loop. I don't have a good explanation as to why your problem is occurring, but I'd like to suggest changing your loop to iterate over an array that's assigned the value of what getMonths was returning.

Related