The issue is caused by package @angular/….
"@angular/animations": "~10.1.4",
"@angular/common": "~10.1.4",
"@angular/compiler": "~10.1.4",
"@angular/core": "~10.1.4",
"@angular/forms": "~10.1.4",
"@angular/platform-browser": "~10.1.4",
"@angular/platform-browser-dynamic": "~10.1.4",
"@angular/router": "~10.1.4",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
Description
Dev server error is present when template error is fixed
🔬 Minimal Reproduction
install the latest version of @angular/cli
I am using
"@angular/cli": "~10.1.4",
create a brand new app like
In app.component.html, copy and paste the following line inside of the main content div:
<h1 [style.color]="'red'">Hello World!</h1>
Change the first double quote to single quote to cause the template error. Then change it back to double quote to fix it.
In the terminal, these errors are shown:
ERROR in src/app/app.module.ts:9:5 - error NG6001: The class 'AppComponent' is listed in the declarations of the NgModule 'AppModule', but is not a directive, a component, or a pipe. Either remove it from the NgModule's declarations, or add an appropriate Angular decorator.
9 AppComponent
~~~~~~~~~~~~
src/app/app.component.ts:8:14
8 export class AppComponent {
~~~~~~~~~~~~
'AppComponent' is declared here.
src/app/app.component.html:417:25 - error NG8002: Can't bind to 'ngSwitch' since it isn't a known property of 'div'.
417 <div class="terminal" [ngSwitch]="selection.value">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/app.component.ts:5:16
5 templateUrl: './app.component.html',
~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AppComponent.
src/app/app.component.html:535:1 - error NG8001: 'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular component, then verify that it is part of this module.
2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
535 <router-outlet></router-outlet>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/app.component.ts:5:16
5 templateUrl: './app.component.html',
~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AppComponent.
You can read more about issue submission guidelines here:
🌍 Your Environment
It’s a brand new angular app as of 10/6/2020:
«dependencies»: {
«@angular/animations»: «~10.1.4»,
«@angular/common»: «~10.1.4»,
«@angular/compiler»: «~10.1.4»,
«@angular/core»: «~10.1.4»,
«@angular/forms»: «~10.1.4»,
«@angular/platform-browser»: «~10.1.4»,
«@angular/platform-browser-dynamic»: «~10.1.4»,
«@angular/router»: «~10.1.4»,
«rxjs»: «~6.6.0»,
«tslib»: «^2.0.0»,
«zone.js»: «~0.10.2»
},
«devDependencies»: {
«@angular-devkit/build-angular»: «~0.1001.4»,
«@angular/cli»: «~10.1.4»,
«@angular/compiler-cli»: «~10.1.4»,
«@types/node»: «^12.11.1»,
«@types/jasmine»: «~3.5.0»,
«@types/jasminewd2»: «~2.0.3»,
«codelyzer»: «^6.0.0»,
«jasmine-core»: «~3.6.0»,
«jasmine-spec-reporter»: «~5.0.0»,
«karma»: «~5.0.0»,
«karma-chrome-launcher»: «~3.1.0»,
«karma-coverage-istanbul-reporter»: «~3.0.2»,
«karma-jasmine»: «~4.0.0»,
«karma-jasmine-html-reporter»: «^1.5.0»,
«protractor»: «~7.0.0»,
«ts-node»: «~8.3.0»,
«tslint»: «~6.1.0»,
«typescript»: «~4.0.2»
}
|
# |
|
Date 07.04.2021 |
Views 46.566 |
Error Message in
VSCode Terminal:
Error: src/app/xxx.component.html:24:5
— error NG8001: ‘mat-icon’ is not a known element:
1. If ‘mat-icon’ is an Angular component,
then verify that it is part of this module.
2. If ‘mat-icon’ is a Web Component then
add ‘CUSTOM_ELEMENTS_SCHEMA’ to the ‘@NgModule.schemas’ of this component to
suppress this message.
24
<mat-icon>home</mat-icon>
~~~~~~~~~~
src/app/articles/read-article/read-article.component.ts:13:16
13 templateUrl:
‘./read-article.component.html’,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component
ReadArticleComponent.
solution:
You have to
insert the missing module in app.modules.ts
In this case, it
is the mat-icon -> MatIconmodule
from @angular/material/icon
ClientApp/src/app/
<div >
<button mat-fab color=»warn» aria-label=»Example icon button with a home
icon»>
<mat-icon>home</mat-icon>
</button>
</div>
app.module.ts
import { BrowserModule } from ‘@angular/platform-browser’;
import { NgModule } from ‘@angular/core’;
import { FormsModule } from ‘@angular/forms’;
import { HttpClientModule, HTTP_INTERCEPTORS }
from ‘@angular/common/http’;
//*Material-UI
//*@Angular-Material
import { MatIconModule } from ‘@angular/material/icon’;
import { MatButtonModule } from ‘@angular/material/button’;
//*routing replaces import {
RouterModule } from ‘@angular/router’;
import { AppRoutingModule } from ‘./app-routing.module’; //*Routing in app-routing.module.ts
//Asp Auth Identiy
import { ApiAuthorizationModule } from ‘src/api-authorization/api-authorization.module’;
import { AuthorizeGuard } from ‘src/api-authorization/authorize.guard’;
import { AuthorizeInterceptor } from ‘src/api-authorization/authorize.interceptor’;
//App Components
import { AppComponent } from ‘./app.component’;
import { NavMenuComponent } from ‘./nav-menu/nav-menu.component’;
import { HomeComponent } from ‘./home/home.component’;
import { ListArticlesComponent } from ‘./articles/list-articles/list-articles.component’;
import { EditArticleComponent } from ‘./articles/edit-article/edit-article.component’;
import { ReadArticleComponent } from ‘./articles/read-article/read-article.component’;
@NgModule({
declarations: [
AppComponent,
NavMenuComponent,
HomeComponent,
ListArticlesComponent,
EditArticleComponent,
ReadArticleComponent,
],
imports: [
BrowserModule.withServerTransition({ appId: ‘ng-cli-universal’ }),
HttpClientModule,
FormsModule,
MatIconModule, //*FAB
Button
MatButtonModule, //*FAB Button
ApiAuthorizationModule,
AppRoutingModule
],
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: AuthorizeInterceptor, multi: true }
],
bootstrap: [AppComponent]
})
export class AppModule { }
dtrunk90
free
asked 2 years ago
I am trying to use the select with searchbox example but getting the following error message:
src/app/app.component.html:11:15 - error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'mdb-select-filter'.
1. If 'mdb-select-filter' is an Angular component and it has 'ngModel' input, then verify that it is part of this module.
2. If 'mdb-select-filter' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
11 [ngModel]="searchText | async"
~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/app.component.ts:7:16
7 templateUrl: './app.component.html',
~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AppComponent.
My app.module.ts file:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MDBBootstrapModulesPro, MDBSpinningPreloader, MdbSelectModule } from 'ng-uikit-pro-standard';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
MDBBootstrapModulesPro.forRoot(),
MdbSelectModule
],
providers: [
MDBSpinningPreloader
],
bootstrap: [AppComponent]
})
export class AppModule { }
My app.component.ts file:
import { Component, OnInit } from '@angular/core';
import { Subject, Observable } from 'rxjs';
import { startWith, map } from 'rxjs/operators';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'web';
searchText = new Subject();
filteredOptions: Observable<any[]>;
options = [
{ value: '1', label: 'Option 1' },
{ value: '2', label: 'Option 2' },
{ value: '3', label: 'Option 3' },
];
ngOnInit() {
this.filteredOptions = this.searchText.pipe(
startWith(''),
map((value: string) => this.filter(value))
);
}
filter(value: string): any[] {
const filterValue = value.toLowerCase();
return this.options.filter((option: any) => option.label.toLowerCase().includes(filterValue));
}
}
And finally the HTML:
<div class="md-form">
<mdb-select-2 placeholder="Choose your option" label="Example label">
<mdb-select-filter
[ngModel]="searchText | async"
(ngModelChange)="searchText.next($event)">
</mdb-select-filter>
<mdb-select-option *ngFor="let option of filteredOptions | async" [value]="option">{{ option.label }}</mdb-select-option>
</mdb-select-2>
</div>