1

I am trying to build an app using "An API of Ice and Fire". I am getting this error ERROR Error: "[object Object]" when I try to redirect to homeComponent. Here is the screenshot of the error:

Before redirecting to home

on home

Ah, one more thing, I think the shell page is not getting redirected to the homepage, because the URL doesn't change to http://localhost:4200/home.

I am attaching the plunk of my code. Please help. Thanks.

8
  • How can the error be reproduced in plunker ? Commented Jul 13, 2018 at 10:03
  • It shows a { error in scripts.js. Where is that file? Commented Jul 13, 2018 at 10:03
  • I can see the error in console. Please share me your code. Commented Jul 13, 2018 at 10:04
  • @AdrianFâciu The plunk was just to have a look at my code. I am not sure how else to show it. Commented Jul 13, 2018 at 10:06
  • @Code_maniac: I am not sure about the file because when I click on it, it redirects me to "//! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css " with some CSS code. Commented Jul 13, 2018 at 10:13

1 Answer 1

1

Finally found out the reason :). I forgot to import and include HttpClient in my app.module.ts file and imports array, making it inaccessible to the app (I think so).

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

//Router Module for Application level Route
import { RouterModule,Routes } from '@angular/router';

import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { BookViewComponent } from './book-view/book-view.component';

//import statement for service
import { BookService } from './book.service';
import { BookHttpService } from './book-http.service';

import { HttpClientModule } from '@angular/common/http'; 

//decorators
@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    BookViewComponent,
  ],
  imports: [
    BrowserModule,
    RouterModule.forRoot([
      { path: 'home', component: HomeComponent },
      { path: 'book/:isbn', component: BookViewComponent }
    ]),
    HttpClientModule
  ],
  providers: [BookService,BookHttpService],
  bootstrap: [AppComponent]
})

export class AppModule { }

I forgot to include this module import { HttpClientModule } from '@angular/common/http';

But the 2nd error is still in place. SyntaxError: unexpected token: '{' scripts.js:1:5 . I can't understand why is this an error.

angular.json file:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "series": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/series",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"

            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "series:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "series:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "series:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "series-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "series:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "series:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "series"
}
Sign up to request clarification or add additional context in comments.

5 Comments

Because you included styles file in scripts array of angular.json file. They go in styles array
@Code_maniac I removed the CSS files but the error is still there.
Need to see your angular.json file
Do you have any scripts.js file? Going by the screeenshot, it shows that your js file actually has a css content.
@Code_maniac Thanks, it was throwing the error due to the css file in scripts array,as you said. Now, it's working fine. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.