1
votes

A warning message shows up when a for loop is used inside of a subscription (when I delete the for loop, the warning dissapear). I was trying to convert a Timestamp from SQL into a number readable for angular, i find a workaround but a warning appears

import { stringify } from '@angular/compiler/src/util';

getUserTasks() {
    this.tasksSubscription = this.userService.getUserTasks(3).subscribe(tasks => {
      this.tasks = tasks;
      for (var ta of this.tasks) {
        let str = ta.startDate.split("[");
        let time = new Date(str[0]);
        ta.startDate = stringify(time.getTime());
      }
      this.TaskDataSource.data = this.tasks;
      this.isLoading = false;
    }
    );
  }

WARNING :

WARNING in ./node_modules/@angular/compiler/src/util.js 10:24-31

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

2

2 Answers

1
votes

I cannot see the rest of the code, but usually that warning is prompted when you are not importing something correctly. I see you are using the stringify function inside of the for loop, so it could be because of that. Could you share the import line for the stringify function?

0
votes

Yes, I had the same issue importing the stringify and removing it fixed the error.