I am learning Angular2 RC5
with Angular2 material libraries and getting it to run in a AspNetCore 1.0
app using VisualStudio 2015.
I took a perfectly running Angular2 RC5
single page application and tried to introduce lazy loading where only the login page will load first. When I have successfully logged in, I want to load the remaining pages.
When I clicked on the login button in SPA mode, I would redirect successfully to the DashboardComponent page which was preloaded with the login page - that was before I introduced lazy loading. After following this tutorial I now get these errors
Error Snippet
EXCEPTION: Error: Uncaught (in promise): Template parse errors: Can't bind to 'ngIf' since it isn't a known property of 'md-card-title'. 1. If 'md-card-title' is an Angular component and it has 'ngIf' input, then verify that it is part of this module. 2. If 'md-card-title' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message. (" <md-card-title [ERROR ->]*ngIf="!showMessage && !isApproved"> Please use the information below... </md-card-title> "): ReportListComponent@63:23 Property binding ngIf not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "directives" section. ("
Why is the ngIf directive suddenly not working? It was working before I moved the Dashboard to load lazily post the login success.
I have gone all the way till using the Shared modules approach in the link I posted above. Is not using the Shared modules a cause for this issue? I presumed module sharing to be a way to clean up the code and not repeat stuff once everything works and nothing more than that.
My Dashboard is similar to the HeroesList page in the link I am following above, where in it loads some more pages the minute the DashboardModule is loaded. I have put breakpoints in the Dashboard page on the MVC side and have confirmed that the Dashboard and pages after does load lazily only on a successful login.
The error seems like its not able to get the reference of core angular references and/or angular2 material libraries. I have put all of those imports listed here in all the modules that would have them other than the routing modules
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { MdRadioModule } from '@angular2-material/radio';
import { MdToolbarModule } from '@angular2-material/toolbar';
import { MdButtonModule } from '@angular2-material/button';
import { MdIconModule } from '@angular2-material/icon';
import { MdProgressBarModule } from '@angular2-material/progress-bar';
import { MdListModule } from '@angular2-material/list';
import { MdInputModule } from '@angular2-material/input';
import { MdCardModule } from '@angular2-material/card';
Still I get the errors as in the snippet above. What could I be missing? Any help or tips appreciated.
EDIT
Dashboard.Module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { MdRadioModule } from '@angular2-material/radio';
import { MdToolbarModule } from '@angular2-material/toolbar';
import { MdButtonModule } from '@angular2-material/button';
import { MdIconModule } from '@angular2-material/icon';
import { MdProgressBarModule } from '@angular2-material/progress-bar';
import { MdListModule } from '@angular2-material/list';
import { MdInputModule } from '@angular2-material/input';
import { MdCardModule } from '@angular2-material/card';
import { AppService } from './app.service';
import { DashboardRoutingModule } from './Dashboard-routing.Module';
@NgModule({
imports: [
CommonModule, HttpModule, FormsModule, RouterModule,
MdRadioModule, MdToolbarModule, MdProgressBarModule,
MdButtonModule, MdIconModule, MdListModule,
MdCardModule, MdInputModule, MdToolbarModule,
DashboardRoutingModule],
/*declarations: [ DashboardComponent ],*/
exports: [ CommonModule ],
providers: [ AppService ]
})
export class DashboardModule { }
DashBoardComponent.ts
import { Component } from '@angular/core';
import { AppService } from './app.service';
@Component({
template: `
<router-outlet></router-outlet>
`
})
export class DashboardComponent {
userName = '';
constructor(service: AppService) {
//this.userName = service.userName;
}
}
dashboard-routing.Module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { MdRadioModule } from '@angular2-material/radio';
import { MdToolbarModule } from '@angular2-material/toolbar';
import { MdButtonModule } from '@angular2-material/button';
import { MdIconModule } from '@angular2-material/icon';
import { MdProgressBarModule } from '@angular2-material/progress-bar';
import { MdListModule } from '@angular2-material/list';
import { MdInputModule } from '@angular2-material/input';
import { MdCardModule } from '@angular2-material/card';
import { DashboardComponent } from './DashBoardComponent';
import { ReportListComponent } from './ReportListComponent';
import { ReportDetailComponent } from './ReportDetailComponent';
const routes: Routes = [
{
children: [
{ path: 'Home/ReportList', component: ReportListComponent },
{ path: 'Home/ReportDetail/:reportId', component: ReportDetailComponent }
]
}
];
@NgModule({
imports: [RouterModule.forChild([routes])
],
declarations: [ DashboardComponent, ReportListComponent, ReportDetailComponent ],
exports: [RouterModule, ReportListComponent, ReportDetailComponent, CommonModule]
})
export class DashboardRoutingModule {}
Dashboard
component is now part of another module and you need to import CommonModule
to that module in order to use *ngIf
directive. You don't need to import CommonModule
to your AppModule
because you import BrowserModule
there, and BrowserModule
imports and then exports CommonModule
, which means you get CommonModule
automatically when you import BrowserModule
.
Today i have encountered such an error with ionic 5 it was because i had deleted the router line that was in charge of this page cause it was a modal.. None of *ngIf nor *ngFor were working until I put there links back inside the app.routing file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With