Why is my Angular 2 app (TypeScript) not functioning properly?

My current project includes a component called EventListComponent

import { Component } from 'angular2/core';

@Component ({
    selector: 'el-events',
    templateUrl: 'app/events/event-list.component.html'
})

export class EventListComponent {
    pageTitle: string = 'Events List';
}

The EventListComponent component should be displayed in the AppComponent

import { Component } from 'angular2/core';
import { EventListComponent } from './events/event-list.component';

@Component({
    selector: 'events-app',
    template: `
    <div>
        <h1>{{pageTitle}}</h1>
        <el-events></el-events>
    </div>`,
    directives: [ EventListComponent ]
})

export class AppComponent {
    pageTitle: string = 'Local Events App';
}

IDE confirms that the directives, selectors, import/export, and decorators are set up correctly. Although, I am using an older version of Angular 2 that requires directives as per course requirements.

Upon testing, I discovered that the page is not rendering the components as expected. The errors displayed are as follows: https://i.sstatic.net/hERJv.png

The project tree structure is illustrated in the following image: https://i.sstatic.net/Rx1zT.png

Upon further investigation, I found that the error occurs when I add the directives section, which could possibly be the root cause of the issue. The Angular version being used is:

"dependencies": {
"angular2": "2.0.0-beta.15"
}

Update Index.html

<!DOCTYPE html>
<html>

<head>
    <title>Local Events App</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="node_modules/bootstrap/dist/css/bootstrap.css" rel="stylesheet" />
    <link href="app/app.component.css" rel="stylesheet" />

    <!-- 1. Load libraries -->
    <!-- IE required polyfills, in this exact order -->
    <script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="node_modules/systemjs/dist/system-polyfills.js"></script>

    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>

    <!-- 2. Configure SystemJS -->
    <script>
        System.config({
        packages: {        
          app: {
            format: 'register',
            defaultExtension: 'js'
          }
        }
      });
      System.import('app/main')
            .then(null, console.error.bind(console));
    </script>
</head>

<body>
    <events-app>
        Loading App...
    </events-app>
</body>

</html>

event-list.component.html

<div class 'panel panel-primary'>
    <div class='panel-heading'>
        {{pageTitle}}
    </div>
    <div class='panel-body'>
        <div class='row'>
            <div class='col-md-2'></div>
            <div class='col-md-4'>
                <input type="text" />
            </div>
        </div>
        <div class='row'>
            <div class='col-md-6'>
                <h3>Search by: </h3>
            </div>
        </div>
    </div>
    <div class='table-responsive'>
        <table class='table'>
            <thead>
                <tr>
                    <th>
                        <button class='btn btn-primary'>
                            Show image
                        </button>
                    </th>
                    <th>Event</th>
                    <th>Code</th>
                    <th>Date</th>
                    <th>Fee</th>
                    <th>Rating</th>
                </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
    </div>
</div>

Answer №1

You need to include an = in your event-list.component.html

<div class 'panel panel-primary'>

The correct syntax is

<div class='panel panel-primary'>

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

I'm curious if there is a method to implement Angular Datatables that includes a filter for every column in a more streamlined and efficient manner?

Incorporating Angular 7 and Angular DataTables "the angular way", I aim to implement individual column filters similar to "Individual column searching" as demonstrated here: , which is presented as a non-angular approach. My attempts to merge "the angular ...

When the Firebase "value" event is triggered, both the "then" and "catch" functions will be called simultaneously

Seeking clarity, I am utilizing two interconnected functions and incorporating error-handling techniques. The then and catch for function A() are functioning correctly. However, the issue arises with function B() where both then and catch are being trigger ...

What causes two variables of identical types to exhibit varying behaviors based on their creation methods?

What causes the types of tuple and tuple2 to be different even though both nums and nums2 are of type (0 | 1 | 2)[]? // const nums: (0 | 1 | 2)[] const nums: (0 | 1 | 2)[] = []; // let tuple: (0 | 1 | 2)[] let tuple = [nums[0], nums[1]]; // const nums2: ...

The ng test option is failing to execute effectively

Attempting to conduct unit tests utilizing Karma and Jasmine through the ng test is proving to be a bit challenging. Upon issuing the following command: ng test --watch=false --code-coverage --main ./src/main/resources/public/scripts/xyz/workspace/commons ...

Is jest the ideal tool for testing an Angular Library?

I am currently testing an Angular 9 library using Jest. I have added the necessary dependencies for Jest and Typescript in my local library's package.json as shown below: "devDependencies": { "@types/jest": "^25.1.3", "jest": "^25.1.0", ...

The setInterval function is active in various components within Angular 6

Recently, I started using Angular(6) and incorporated the setInterval function within a component. It's functioning properly; however, even after navigating to another route, the setInterval continues to run. Can someone help me determine why this is ...

Creating an array object in TypeScript is a straightforward process

Working on an Angular 4 project, I am attempting to declare an attribute in a component class that is an object containing multiple arrays, structured like this: history: { Movies: Array<Media>, Images: Array<Media>, Music: Array<Medi ...

Tips for maintaining consistent column size in an angular material table as the screen size shrinks

I have a material table with 9 columns and I want to keep the column size consistent even when the screen size is reduced. Currently, as I decrease the screen size, the last column shrinks first while the other columns remain the same size, creating an un ...

A guide on implementing code sharing in NestJS using Yarn Workspaces

I'm currently working on a proof of concept for a basic monorepo application. To structure my packages, I've decided to use Yarn Workspaces instead of Lerna as it seems more suitable for my needs. One of the packages in my setup is shared, which ...

Utilize ServersideProps to input data into the server-side

Can data be retrieved from the server-side configuration file on the client using getServersideProps() in Next.js? What is the best way to send this data as props or retrieve it in a different manner on the client side? I attempted to use publicRuntimeCo ...

Angular and RxJS can be set up to delay the next call from BehaviorSubject in situations where there are multiple

Within my Angular application, I maintain a state using a service that stores the data as a BehaviorSubject. Whenever new data is received from the server, the next function is called to update the existing data and notify all subscribers. PseudoCode: ...

Using Firestore to Query and Subscribe to Multiple Documents using an Array of IDs

Despite the limitations in querying multiple documents based on an Array of IDs, I frequently encounter situations where it becomes necessary. In this particular instance, I am faced with the challenge of selecting a random list of IDs which I believe is ...

Having trouble closing my toggle and experiencing issues with the transition not functioning properly

Within my Next.js project, I have successfully implemented a custom hook and component. The functionality works smoothly as each section opens independently without interfering with others, which is great. However, there are two issues that I am facing. Fi ...

What is the process for utilizing a user AD account with SecretClient in a node/TypeScript environment?

Currently, I am faced with authentication challenges while attempting to utilize the Azure Key Vault Secret client library (https://www.npmjs.com/package/@azure/keyvault-secrets). Most of the examples provided involve service principal usage, but my requ ...

Eliminating empty elements from arrays that are nested inside other arrays

I am facing a challenge with the array structure below: const obj = [ { "description": "PCS ", "children": [ null, { "name": "Son", ...

The chart is failing to refresh with the latest response information (using Chart.js version 3.2.1 and ng2-charts version 3.0.0-beta.9)

I recently upgraded my project using Chart.js version 3.2.1 and ng2-charts version 3.0.0-beta.9. Initially, everything seemed to be working fine with mock data - the charts were displaying as expected. However, when I switched to testing with real backend ...

Dealing with DomSanitizer problem in Angular 2

When using background-image inline for my *ngFor list items, I encountered an issue. In my Component Class, I defined a variable to store a common part of the images' URLs (e.g., ) along with unique parts of the image URLs as this.image (such as qwer ...

Error TS2304: Unable to locate identifier 'RTCErrorEvent'

I am currently working on a WebRTC application using Quasar, typescript and Vue. In my code snippet below, I am encountering an issue where I don't get any errors in WebStorm (as it uses the project's eslint config), and I can navigate to the def ...

Utilizing JSDoc annotations for type safety in VSCode with ESLint configuration for TypeScript declarations import

Is there a way to configure VSCode to perform syntax checking on .eslintrc.js and provide autocomplete functionality? I have managed to set up a structure for a JavaScript configuration file with a custom syntax for my application, but the same approach do ...

Error in executing a function within an asynchronous function sequence

Whenever a user logs in, I want to update their data in Firestore. However, the code I am using does not seem to work as expected. It fails to create a custom User object from the firebase.User. Can anyone help me understand why this is happening and how ...