The Reason Behind Angular Error when Using CSS Custom Tags

I have the following SCSS code:

main{
    width: 100%;
    height: 840px;
    /*background: red;*/
    margin: 10px auto;
    position: relative;
    padding: 5px 0;
}
section{
    width: 98%;
    height: 600px;      
    margin: auto;
    display: flex;
    align-items: center;
    overflow-x: auto;
}
....

and this HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Simple responsive test</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <main>
        <div class="text">
            <h1>Simple Test</h1>
            <p>
                Lorem ipsum dolor sit amet consectetur adipisicing elit. Veniam non atque adipisci est, recusandae aperiam, ullam minima quos nostrum animi voluptas sequi. At repellendus fuga reiciendis accusantium, dolor suscipit repellat?
            </p>
        </div>
        <section>
            <div class="product">
                <img src="image/banner2.png" alt="">
                <p>
                    <b>Product One</b><br>
                    <small>New arrival</small>
                </p>
                <samp>$45.00</samp>
            </div>
       </section>
   </main>
</body>

In regular HTML, the browser renders the layout correctly.

However, when using Angular, we encounter an error main is not recognized. Is there any specific action needed in Angular to resolve this issue?

The error message is as follows:

error NG8001: 'main' is not a known element:
1. If 'main' is an Angular component, then verify that it is part of this module.
2. If 'main' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

                  <main>


</main>

Answer №1

Ensure that your Component is imported in the AppModule, or in the module that imports your Component.

Don't forget to include CommonModule and BrowserModule in your AppModule as well. This may be causing the issue.

Your AppModule should look something like this:

@NgModule({
  declarations: [
    YourComponent,
    AppComponent
  ],
  imports: [
    CommonModule,
    BrowserModule
    // any other necessary modules
  ],
  .........
 })
 export class AppModule {
    }

However, I recommend creating a separate Module for your components and importing that into your AppModule.

// components.module.ts (or choose another name)

import { NgModule }      from '@angular/core';
import { CommonModule } from '@angular/common';
import { YourComponent}  from './YourComponent/your-component.component.ts';

@NgModule({
  imports:      [ CommonModule  ],
  declarations: [ YourComponent],
  exports:    [ YourComponent]
})
export class ComponentsModule{ }

// app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }  from './app.component';
import { ComponentsModule } from './components/components.module.ts'

@NgModule({
  imports:      [ BrowserModule, ComponentsModule  ],
  declarations: [ AppComponent ],
  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

Load the flexslider once the fancybox container is opened

In my experience, I have found flexslider and fancybox to be very useful plugins. Individually, they work perfectly fine on a website that I am currently working on. However, when I tried placing a flexslider gallery inside a fancybox div, I encountered a ...

Problem with Jasmine in Angular 5 within Visual Studio Code

I am completely new to Angular 5 Unit testing and facing some challenges. Despite installing all @types/jasmine, I am encountering errors in my spec.ts file such as 'describle is not a name' and 'jasmine.createSpyObj does not exist on the ty ...

Issues with HTML formatting in PHP emails

I am sending an approval/disapproval email to a user. I want to include a button in the email so that when the user clicks it, they can approve or disapprove the request. However, I am facing an issue as I cannot see the button in the mail when I receive ...

Using Mat-Error for Two Way Binding leads to frequent triggering of ngModelChange事件

I am working with a mat input field that has two-way data binding using ngModel, and I want to add validation using mat-error and formControl. <mat-form-field [formGroup]="myForm"> <input matInput formControlName="myFormName" autocomplete="off" ...

Identifying the precise image dimensions required by the browser

When using the picture tag with srcset, I can specify different image sources based on viewport widths. However, what I really need is to define image sources based on the actual width of the space the image occupies after the page has been rendered by th ...

Tips for streamlining interface initialization and adding items to it

I have designed an interface that includes another interface: export interface Parent { children: Child[]; } export interface Child { identifier: string; data: string; } Is there a more efficient way to initialize and add items to the array? Curren ...

Utilizing CSS to dynamically update SVG icons within the navigation menu upon tab selection

Feeling frustrated and in need of assistance with my current issue. I am attempting to make a change - when I click on a tab in the menu, the default black SVG icon should be replaced by a white one. #menu a .main-menu-icon { display:inline-block; width:2 ...

Trigger parent Component property change from Child Component in Angular2 (akin to $emit in AngularJS)

As I delve into teaching myself Angular2, I've encountered a practical issue that would have been easy to solve with AngularJS. Currently, I'm scouring examples to find a solution with Angular2. Within my top-level component named App, there&apos ...

The issue with Angular 4 imports not refreshing in a .less file persists

Currently, I am in the process of developing a small Angular project that utilizes less for styling purposes. My intention is to separate the styling into distinct folders apart from the components and instead have a main import file - main.less. This fil ...

Creating a bespoke Bootstrap 4 Modal experience without the backdrop

I'm attempting to show a Bootstrap 4 modal without a backdrop. I've tried the following code with no success: .modal.right. modal-backdrop.show { background-color: transparent !important; } When I try this modification, it works (but affect ...

Verify user credentials during login in a React application

My current challenge involves setting up a hardcoded authentication in React for user login using a form. Despite meeting the requirements for the "if" statement, it always returns the "else" statement. I am attempting to pass both the handleSubmit functi ...

an online platform design

I am currently working on building a webpage, but I am facing some issues with the layout. Specifically, I am unable to make the div automatically adjust its size (particularly the height). Here is the code that demonstrates the problem: <!DOCTYPE html ...

Scale up the font size for all text on the website uniformly

Recently, I decided to switch a website's font to a non-web typeface. However, I quickly realized that the font was extremely thin and difficult to read. I attempted a simple CSS fix using * { font-size:125% }, but unfortunately, it did not have the d ...

What is the best way to determine the actual height of a DOM element that is being hidden by the overflow property in order to create a seamless CSS transition to height: auto

Solution: Thanks to @Kalimah, here's a solution that works in composition api & script setup: <script setup> const state = reactive({ meetCardHeight: 100 }) const element = ref(null) const changeElementHeight = () => { if (stat ...

The dropdown height feature is experiencing issues in the Chrome browser

3 radio buttons and a single select box are displayed on the page. When clicking on the first radio button, the select box should show contents related to the first radio button. However, when selecting the second or third radio buttons, the select box hei ...

The anchor tag seems to be malfunctioning within the div container

<style type="text/css> .xyz { position: absolute; top: 120px; left: 160px; z-index: -1; } #container { position: relative; overflow: visible; opacity: .3; } </style> <body> <div> <video i ...

[attr.disabled]="isChecked ? '' : 'disabled'"

[attr.disabled]="isChecked == true ? '' : disabled" Can anyone assist me with disabling unchecked checkboxes in a loop using Angular 8? [attr.disabled]="isChecked == true ? '' : disabled". Need help with this in Ang ...

Utilizing Partial Types in TypeScript Getter and Setter Functions

Within the Angular framework, I have implemented a component input that allows for setting options, specifically of type IOptions. The setter function does not require complete options as it will be merged with default options. Therefore, it is typed as Pa ...

Is it possible for a malicious party to modify the src attribute within an iframe?

My website incorporates IFrame on a page, loading different pages based on server-side logic. As such, the source code appears like this when viewed: <iframe src="DeterminedOnServerSide.aspx" id="myFrame"> </iframe> I am curious if there is a ...

Add a unique shape to the CSS clip property

Recently, I've been delving into the clip property of CSS and its ability to apply a rectangle or square object. Despite my research efforts, I haven't come across a clear answer to my question. Can you actually use a customized shape with the c ...