Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I using RC5 ngModule

app.module.ts

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 {}

profile.module.ts

    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 {}

and new.profile.component.ts

 ///<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);
            })
    }

}

but in template to NewProfileComponent if use *ngIf happens compilation error: Can't bind to 'ngIf' since it isn't a known property of 'p'

any idea?

share|improve this question
    
import NewProfileComponent from './new.profile.component'; should be import {NewProfileComponent} from './new.profile.component'; – micronyks Sep 1 at 3:08

ngIf directive is contained by CommonModule and you are not exporting it in profileModule.

So, you just 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 {}
share|improve this answer
    
it's works, thanks... – Carlos Eduardo Souza Sep 2 at 2:05
    
Glad it worked for you. – micronyks Sep 2 at 5:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.