Error in routing syntax, angular 2 zone symbol misconfiguration

Encountered an error while attempting to route my app:

metadata_resolver.js:972 Uncaught 
SyntaxError {__zone_symbol__error: Error: Unexpected value '[object Object]' imported by the module 'AppModule' at SyntaxError.Zone……}

app.component.html

<div class='container-fluid form-inline'>
   <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
            <span id='title' class='btn btn-primary input-group'><b>{{title}}</b></span>
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
           <b> Menu</b>
          </button>
          <!-- search box start-->

          <div id="search" class="input-group col-xs-6 pull-right form-inline">
              <input type="text" class="  search-query form-control" placeholder="Search" />
              <span class="input-group-btn">
                  <button class="btn btn-primary" type="button">
                      <span class=" glyphicon glyphicon-search"></span>
                  </button>
              </span>
          </div>

          <!-- search box End -->
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="index.html"><b>Home</b></a></li>
            <li><a href="about.html"><b>All Events</b></a></li>
            <li class="dropdown">
              <a class="dropdown-toggle" data-toggle="dropdown" href="calendar.html"><b>Events</b> <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="tag.html">Categories</a></li>
              </ul>
            </li>
            <li><a href="services.html"><b>Create Event</b></a></li>
          </ul>
        </div>
      </div>
    </nav>
</div>
<br><br><br><br>
<div class='container-fluid'>
<div class='row'>
    <div  class='col-md-6'>
        <router-outlet></router-outlet>    

<div *ngFor='let event of events'>
    <EventThumbnailComponent [event2]="event" (eventClick)='handleEventClicked($event)'>Hello</EventThumbnailComponent></div></div></div>
    <button class='btn btn-primary' (click)="triggerAlert()">alert id</button>
    <button class='btn btn-primary' (click)='triggerClickMe()'>click me!</button>
</div>

app.modules.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { EventListComponent } from './event-list/event-list.component';
import { EventThumbnailComponent } from './event-thumbnail/event-thumbnail.component';
import { EventsService } from './shared/events.service';
import { EventDetailsComponent } from './event-details/event-details.component';
import { RouterModule, Routes } from '@angular/router';
 import { appRoutes } from './routes';

@NgModule({
  declarations: [
    AppComponent,
    EventListComponent,
    EventThumbnailComponent,
    EventDetailsComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    appRoutes
  ],
  providers: [EventsService],
  bootstrap: [AppComponent]
})
export class AppModule { }

routes.ts

import { Routes,RouterModule } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
import { EventListComponent } from './event-list/event-list.component';
import { EventDetailsComponent } from './event-details/event-details.component';

export const router: appRoutes=[
   { path:'events', component :EventListComponent },
    { path:'events/:id', component :EventDetailsComponent },
    { path: '' , redirectsTo : '/events' , pathMatch: 'full' }
    ];

    export const router: ModuleWithProviders= RouterModule.forRoot(router);

Seeking understanding regarding the encountered error and the significance of Zone_symbol_error. Looking for guidance on how to resolve this issue within the provided code.

Answer №1

Ensure that you are importing a preconfigured

router = RouterModule.forRoot(appRoutes)
, not just the configuration appRoutes:

In your routes.ts file, use appRoutes :Routes instead of router: appRoutes, and RouterModule.forRoot(appRoutes) instead of RouterModule.forRoot(router)

import { Routes, RouterModule } from '@angular/router';
import { ModuleWithProviders } from '@angular/core';
import { EventListComponent } from './event-list/event-list.component';
import { EventDetailsComponent } from './event-details/event-details.component';

export const  appRoutes :Routes=[
   { path:'events', component :EventListComponent },
    { path:'events/:id', component :EventDetailsComponent },
    { path: '' , redirectTo : '/events' , pathMatch: 'full' }
    ];
    export const router: ModuleWithProviders= RouterModule.forRoot(appRoutes);

In AppModule: router instead of appRoutes

import { router} from './routes';

@NgModule({
          declarations: [
            AppComponent,
            EventListComponent,
            EventThumbnailComponent,
            EventDetailsComponent
          ],
          imports: [
            BrowserModule,
            FormsModule,
            HttpModule,
            router
          ],
          providers: [EventsService],
          bootstrap: [AppComponent]
        })
        export class AppModule { }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Time for Angular Component Observable Bindings

I came across a similar question elsewhere, but unfortunately, it was left unanswered 1. In my service, I have a scenario where I check local storage for a specific value. If the value exists, I set it as the next value for the Subject; if not, I make an ...

Executing a function defined in a .ts file within HTML through a <script> tag

I am attempting to invoke a doThis() function from my HTML after it has been dynamically generated using a <script>. Since the script is loaded from an external URL, I need to include it using a variable in my .ts file. The script executes successfu ...

Using Jasmine and ReSharper to test TypeScript modules

In my VS2017 project, I have a Jasmine test written in TypeScript: describe("A simple test", () => { it("Should succeed", () => { expect(true).toBeTruthy(); }); }); Everything runs smoothly using the ReSharper test runner. However, when I ...

Having difficulty running lint on Vue 3 TypeScript application, but building process is successful

We are encountering an issue at the moment. We can successfully build our app, but we are facing challenges with linting using the vue tools (vue-cli-service ...). The hot-reloading feature works initially, but upon saving a file, we receive an error mess ...

Travis CI's TypeScript build process detects errors before Mocha has a chance to catch them

Instead of a bug, the TypeScript compiler is doing its job but causing my Travis builds to fail. In my package, I have a function named completeRound which accepts a number as its first argument and 3 optional arguments. Since it's in TypeScript, I s ...

What is the process of mapping an array of object IDs in order to retrieve the corresponding objects associated with each ID

I currently have a specific collection that stores IDs referencing objects in a separate schema. If I'm working with an array containing these IDs, what is the best way to iterate through and retrieve the corresponding object? Although I've mad ...

Ways to retrieve form information from a POST request

I received a POST request from my payment gateway with the following form data: Upon trying to fetch the data using the code snippet below, I encountered errors and gibberish content: this.http .post<any>('https://xyz.app/test', { ti ...

(Angular) Employing *ngFor directive for populating a table

I am in need of a table structure that resembles the following: https://i.sstatic.net/rB2C6.png To achieve this, I am utilizing a basic Bootstrap table along with Angular's *ngFor. Each cell in the table should display a different name from an array ...

Changing the name of a tab within a p-tabview

Setting up a p-tabview with tabs containing specific content involves the following code: <p-tabView class="tabmain" > <ng-container *ngFor="let tab of tabs"> <p-tabPanel [header]="tab.header" > ...

Loop through a FormArray containing FormGroups

I'm struggling with the functionality of my form array containing form groups. My goal is to loop through the form array and display the input fields within each form group. However, when I use addExercise(), the new form group that I add to the arra ...

The Bootstrap model popup darkens the screen, but there are a few areas that remain at the same level of brightness and do not get dim

https://i.sstatic.net/09QtK.png Within my Angular 7 project, I have implemented a Bootstrap modal. However, I am facing an issue where only components with position: relative are darkened when the modal is opened. Some components have position: fixed, as ...

Encountering an error when attempting to iterate over an undefined property using an API

I am trying to fetch all classes and their assignments from Google Classroom. I successfully used Google's example code for listing the classes, but had to write my own code for listing the assignments. While the code runs as expected and lists the as ...

Redefining the type of an existing function in Typescript: A step-by-step guide

If you're looking for a solution where you can declare an existing function without defining an expression, check out this article: . Rather than creating a new function, the goal is to declare the existing function in a similar manner without using t ...

Ionic 2 - Dynamically Loading Segments

I am dealing with categories and dishes. Each dish is associated with a specific category. My goal is to send an http request to retrieve all the dishes belonging to a particular category. This will result in an array like: { Soup[{'Name',&ap ...

Adjust dropdown options based on cursor placement within textarea

I have a textarea and a dropdown. Whenever a user selects an option from the dropdown menu, it should be inserted into the text area. However, I am facing a bug where the selected value is being inserted at the end of the text instead of at the current cur ...

How to retrieve parent data within a dynamic child component in Angular 5

Source Code : https://stackblitz.com/edit/dynamic-child-inside-parent-component Description of the Code : In my project, I have a functionality where child components are dynamically created when a button in the parent component is clicked. The parent co ...

Building a Dynamic Video Element in Next Js Using TypeScript

Is there a way to generate the video element in Next JS using TypeScript on-the-fly? When I attempt to create the video element with React.createElement('video'), it only returns a type of HTMLElement. However, I need it to be of type HTMLVideoEl ...

Unlock the potential of Angular $http by leveraging TypeScript generics in your web development projects

I have been attempting to implement a generic promise return in my code: public getUserData: () => ng.IPromise <string> = () => { var promise = this.makeRequest<string>('http://someurl.com',null) .then((resp ...

Adding a custom property to a React component

Currently, I am facing an issue while attempting to modify an MUI component. Everything works smoothly until I execute the build command, at which point it fails. I have experimented with a few variations of this, but essentially I am looking to introduce ...

Dealing with Type Casting Problems Following the Migration to Angular 4

Following my upgrade to Angular 4, I encountered the error mentioned below [enter image description here][1] client?afea:119 [at-loader] ./src/test/javascript/spec/app/account/settings/settings.component.spec.ts:49:13 TS2322: Type 'Principal&apo ...