Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

record.factory is not a function error on Angular Javascript page

When compiling my app and runnning, the HTML page displays as blank and will not show the app. I was able to use the Inspect tool on Google Chrome and Chrome is saying that record.factory is not a function, the page was working fine. However, I did recently update my angular version to the latest - so I am not sure if that has anything to do with it.

Here's my module.ts code, I suspect it's something with the Imports, usually that has been the case when I run into issues with the app not displaying:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';  
import { ItemService } from './items.service';
import { NewItemFormComponent } from './new-item-form/new-item-form.component';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { Platform } from '@angular/cdk/platform';
import { AutofillMonitor } from '@angular/cdk/text-field';
import { ContentObserver } from '@angular/cdk/observers';

@NgModule({
  declarations: [
    AppComponent,
    NewItemFormComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    BrowserAnimationsModule,
    FormsModule
  ],
  providers: [ItemService, Platform, BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    MatFormFieldModule,
    MatInputModule,
    BrowserAnimationsModule,
    FormsModule, AutofillMonitor, ContentObserver],
  bootstrap: [AppComponent]
})
export class AppModule { }

Any ideas?

like image 951
libracorn Avatar asked Mar 27 '20 22:03

libracorn


People also ask

What is the use of factory in AngularJS?

AngularJS Factory Method makes the development process of AngularJS application more robust. A factory is a simple function which allows us to add some logic to a created object and return the created object. The factory is also used to create/return a function in the form of reusable code which can be used anywhere within the application.

What does the JavaScript error “is not a function” mean?

The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value is not actually a function. Message TypeError: Object doesn't support property or method {x} (Edge) TypeError: "x" is not a function

Why is require () not a function in JS?

JS does not see a semicolon after require (), and we start a line with a (, and JS thinks we’re trying to execute a function. It consider require ('fs') as the name of the function, which is something that could actually work if the module export returned a function. But it’s not, so we get that ...is not a function error.

Where can I find the function in angular core?

This function is located in this file: node_modules\@angular\core\__ivy_ngcc__\fesm5\core.js. At time of writing, the function starts on line 11345. Hope this helps the next poor soul who sees this error.


3 Answers

I had a similar error, this comment's post helped me. It happens when you use packages compiled in different Angular versions:

"Packages must be compiled and ran using the exact same version of Angular; any other combination is not supported and likely to break in subtle ways."

like image 111
Marco Luly Avatar answered Oct 18 '22 19:10

Marco Luly


You have to remove modules from providers array. Remove: BrowserModule, AppRoutingModule, HttpClientModule, MatFormFieldModule, MatInputModule, BrowserAnimationsModule, FormsModule

like image 2
Oscar Ruiz Avatar answered Oct 18 '22 20:10

Oscar Ruiz


You need to comment

@Injectable() in your routing or injecting else

Example

//   @Injectable()  comment this code

 @NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: [] 
 })
like image 1
afeef Avatar answered Oct 18 '22 19:10

afeef