类型错误 Angular:未定义不是函数

Type Error Angular : Undefined is not a function

selectedProjectInfo 是选择项目的数据,其中 ProjectAssignedUsers 然后,我得到 getemployeesList 来自 API 然后用字段 a 修补数据并得到这个错误。

我想实现如果 Id,s 在两个列表中都匹配并且我得到了名字然后这个名字在表单上提交

if(this.selectedProjectInfo.ProjectAssignedUsers)
this.selectedProjectInfo.ProjectAssignedUsers.forEach(
  this.getemployeesList.forEach((cacheEmployee: any) => {
    (backendAssignUser: any) => {
      if (
        cacheEmployee?.Id === backendAssignUser?.UserId &&
        backendAssignUser.UserAssignmentType === 1
      ) {
        this.salesRepList.push({
          FirstName: cacheEmployee?.FirstName,
          LastName: cacheEmployee?.LastName,
          UserTradeNames: cacheEmployee?.UserTradeNames,
          Id: cacheEmployee?.Id,
          UserAssignmentType: 1,

          Color: cacheEmployee?.Color,
        });
      } else if (
        cacheEmployee.Id === backendAssignUser.UserId &&
        backendAssignUser.UserAssignmentType === 2
      ) {
        this.estimatorsList.push({
          FirstName: cacheEmployee?.FirstName,
          LastName: cacheEmployee?.LastName,
          UserTradeNames: cacheEmployee?.UserTradeNames,
          Id: cacheEmployee?.Id,
          UserAssignmentType: 2,
          Color: cacheEmployee?.Color,
        });
      } else if (
        cacheEmployee.Id === backendAssignUser.UserId &&
        backendAssignUser.UserAssignmentType === 3
      ) {
        this.pmList.push({
          FirstName: cacheEmployee.FirstName,
          LastName: cacheEmployee.LastName,
          UserTradeNames: cacheEmployee.UserTradeNames,
          Id: cacheEmployee.Id,
          UserAssignmentType: 3,
          Color: cacheEmployee.Color,
        });
      }
    }
  }),

你弄乱了在数组上使用 forEach 方法的方式。

this.selectedProjectInfo.ProjectAssignedUsers.forEach(
  this.getemployeesList.forEach((cacheEmployee: any) => {

可能您想在第二个 forEach 中进行 1 次嵌套迭代。在那种情况下,正确的方法如下

 this.selectedProjectInfo.ProjectAssignedUsers.forEach(
      (projectAssignedUser: any) => {
        this.getemployeesList.forEach((cacheEmployee: any) => {
              .....
              .....
      }

检查以下简单示例并查看与您的代码中产生的完全相同的错误

var array1 = [1, 2];
var array2 = [3, 4, 5];

array1.forEach(
    array2.forEach((array2Element) => {
             console.log(array2Element);
             }));

虽然以下是您想要并有效的嵌套循环

var array1 = [1, 2];
var array2 = [3, 4, 5];

array1.forEach((array1Element)=> {
    array2.forEach((array2Element) => {
             console.log(array2Element);
             })
});