Exploring the potential of lazy loading with AngularJS 2 RC5 ngModule

I am currently utilizing the RC5 ngModule in my Angular project.

In my app.module.ts file, the import statements and module setup are as follows:

import { NgModule }       from '@angular/core';
import { BrowserModule  } from '@angular/platform-browser';
import { AppComponent }   from './app.component';
import { IndexComponent }   from './index.component';
import {RouterModule} from '@angular/router';

import {MdMenuModule} from '@angular2-material/menu';
import {MdIconModule} from '@angular2-material/icon';
import {MdSidenavModule} from '@angular2-material/sidenav';
import {MdToolbarModule} from '@angular2-material/toolbar';


@NgModule({
    declarations: [AppComponent],
    imports:      [
        BrowserModule, 
        MdMenuModule,
        MdIconModule,
        MdSidenavModule,
        MdToolbarModule,
        RouterModule.forRoot([
            {path: '', component: IndexComponent},
            {path: 'profile', loadChildren: './app/profile/profile.module'}
        ])
    ],
    bootstrap:    [AppComponent],
})
export class AppModule {}

The profile.module.ts file includes the necessary imports for creating a new profile component:

    import {RouterModule} from '@angular/router';
import {NgModule} from '@angular/core';
import NewProfileComponent from './new.profile.component';
import { ReactiveFormsModule } from '@angular/forms';
import ProfileService from './profile.service';

import {MdInputModule} from '@angular2-material/input';
import {MdCardModule} from '@angular2-material/card';
import {MdButtonModule} from '@angular2-material/button';

@NgModule({
  declarations: [ NewProfileComponent ],
  imports: [
    MdInputModule,
    MdCardModule,
    ReactiveFormsModule,
    MdButtonModule,
    RouterModule.forChild([
      { path: 'new', component: NewProfileComponent },
    ])
  ],
  providers: [
    ProfileService
  ]
})
export default class ProfileModule {}

Here is the code from the new.profile.component.ts file which handles the creation of a new profile:

 ///<reference path="../../node_modules/@angular/core/src/metadata/lifecycle_hooks.d.ts"/>
import {Component, OnInit} from '@angular/core';
import ProfileService from './profile.service';

import { FormGroup, FormBuilder, Validators } from '@angular/forms';



@Component({
    selector: 'new-profile-app',
    templateUrl: './app/profile/new.profile.html'
})

export default class NewProfileComponent implements OnInit{

    public registerForm: FormGroup;

    constructor(private formBuilder: FormBuilder, private service: ProfileService) {}

    ngOnInit():any{
        this.registerForm = this.formBuilder.group({
            name: ['', Validators.required],
            email: ['', Validators.required],
            password: ['', Validators.required],
        });
    }



    public save(data: any){
        if(this.registerForm.invalid){
            return;
        }
        this.service.create(data)
            .subscribe(function (response: any) {
                console.debug(response);
            })
    }

}

However, I am encountering a compilation error when using *ngIf in the template of the NewProfileComponent. The error states: Can't bind to 'ngIf' since it isn't a known property of 'p'

Do you have any ideas on how to resolve this issue?

Answer №1

The ngIf directive is located within the CommonModule, but it is not being exported in the profileModule.

To resolve this, you simply need to include it:

import {RouterModule} from '@angular/router';
...
...
import {NewProfileComponent} from './new.profile.component';
import { CommonModule }       from '@angular/common';
...
...

@NgModule({
  declarations: [ NewProfileComponent ],
  imports: [CommonModule,
    ...
    ...
    RouterModule.forChild([
      { path: 'new', component: NewProfileComponent },
    ])
  ],
  providers: [
    ProfileService
  ]
})
export default class ProfileModule {}

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

"Enhancing global accessibility through i18n strategies and evolving language usage

I am looking to update the terminology used in my Angular application. Essentially, I need i18n functionality, but I am not interested in changing the language or implementing localization. The app will remain in English, and I simply want to modify certa ...

Navigating with Angular: Transmitting dynamic URL parameters to components

I currently have the following routes defined: const routes: Routes = [ { path: ':product/new', children: [{ path: 'std/:country', component: SignUpComponent, data: { ...

"What is the best way to apply multiple filters to an array in a React

Is there a way to incorporate dropdown menus along with search text input for filtering an array in React? I would like to give users the option to select a location and then search for specific results within that location. Any suggestions on how to ach ...

Getting the value of the chosen option from one component and passing it to another component in Angular 8

How can I pass the selected option value from the login component to the home component without using local storage? When an option is selected in the login component, I want that value to be displayed in the home component. Below is the code snippet: Lo ...

Improving event observation efficiency with Observable.fromEvent on the browser window

Within my file manager UI, each individual file item is currently set to monitor the window's wheel event. As soon as a file item comes into view on the page, its corresponding image loading process will be initiated by the file item component. While ...

NodeJS on Cloudlinux requires that the node modules for applications be stored in a distinct folder (virtual environment) designated by a symbolic link known as "node_modules"

I recently encountered an issue while trying to deploy my Nodejs/TypeScript web application on my cpanel shared hosting. The error I received stated: * Cloudlinux NodeJS Selector requires the node modules for the application to be stored in a separate f ...

Intercepting 401 with Angular 5 HTTP Interceptor recognizes it as status code 0

One issue I am currently facing is the inability to intercept a 401 status and redirect to the login page, which is a common practice in most applications. My interceptor code seems pretty standard: intercept(request: HttpRequest<any&g ...

Error in TypeScript while running the command "tsd install jquery" - the identifier "document" could not be found

Currently, I am facing an issue with importing jQuery into my TypeScript project. In order to achieve this, I executed the command tsd install jquery --save, which generated a jquery.d.ts file and added /// <reference path="jquery/jquery.d.ts" /> to ...

Navigating Through the Angular Migration Journey

As I was researching how to integrate ES2020 with Angular, I came across the following useful link: https://angular.io/guide/migration-update-module-and-target-compiler-options The document begins by stating "This migration adjusts the target and module s ...

How can TypeScript be forced to output a specific data type?

I've created a generic "fetcher" function that is designed to handle different types of entities. However, I'm encountering an issue where TypeScript is inferring the return type based on all possible conditions within the function. Is there a w ...

When the data is not initialized within the ngOnInit() function, the p-dataTable does not bind properly

In the process of building a form, there is a specific dialog available for users to input data. The dialog functions within a larger form structure. Once the user finishes entering their data in the dialog and clicks on the SAVE button, the entered inform ...

Issue with the recursive function in javascript for object modification

I have all the text content for my app stored in a .json file for easy translation. I am trying to create a function that will retrieve the relevant text based on the selected language. Although I believe this should be a simple task, I seem to be struggl ...

Utilize variable as both a function and an instance of a class

Is there a way to access a variable as both a function and an object instance using TypeScript? log("something"); log.info("something"); I've attempted various methods, such as modifying the prototype, but nothing has proven succ ...

What is the best way to retrieve the data from a specific section when a checkbox is selected in Angular 2?

When I select a checkbox for any section and then click the submit button, I want to display the details of that section in the console. Can someone assist me with this? **Stackblitz link:** : https://stackblitz.com/edit/angular-q7y8k1?file=src%2Fapp%2Fa ...

When attempting to replace the outdated Angular 2 router with the new Router, I encountered an error

I have the main app component and I want to add subroutes under the admin component like /admin/users, /admin/subscribers @Component({ selector: 'my-app', template: `<router-outlet></router-outlet>` directives: [ROUTER_DI ...

Improprove the types generated from GraphQL responses

I am facing a major challenge with the types while using GraphQL. My intention is to send a request and store the result in a React state with a well-defined type. However, I want to avoid declaring it as const [animals, setAnimals] = useState<AnimalsLi ...

The element 'mdb-navbar-brand' in Angular is unrecognized and not known

Encountered this error while working on an Angular project. I'm at a loss on what steps to take next. Can anyone provide assistance? SCRIPT5022: Template parse errors: 'mdb-navbar-brand' is not a known element: 1. If 'mdb-navbar-brand& ...

ts-node: The colon symbol was not expected in this context

As I work on developing a backend server for my application, I made the decision to switch from using babel-node as the executor to utilizing ts-node. The command defined in my package.json file is: "server": "cd server && ts-node --project tsconf ...

Guide on linking an XML reply to TypeScript interfaces

Currently, I am faced with the task of mapping an XML response (utilizing text XMLHttpRequestResponseType) from a backend server to a TypeScript interface. My approach has been to utilize xml2js to convert the XML into JSON and then map that JSON to the Ty ...

Adding dropdowns to divs in Angular applications

Currently, I am attempting to integrate a dropdown feature into a div element. The HTML code for the dropdown is generated dynamically within the code. When clicking on the dropdown button, it appears functional but unfortunately, the dropdown itself does ...