I am developing an node app with angular2 and gulp. I have written a component file login.ts as follows:
import {Component, View} from \'angular2/angular2\';
'angular2/angular2' is not a valid dependencies of angular2
you have to first check package.json file "@angular/core" exist or not
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "2.0.0",
"@angular/router-deprecated": "2.0.0",
"@angular/upgrade": "2.0.0",
.....
}
see the component file like this and also you have too use formGroup as belove
import { Component, OnInit, DoCheck } from '@angular/core'
import { Router } from '@angular/router'
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'
@Component({
selector: 'app-user-profile',
templateUrl: './user-profile.component.html',
styleUrls: ['./user-profile.component.scss'],
})
export class UserProfileComponent implements OnInit, DoCheck {
profileForm: FormGroup
constructor(private fb: FormBuilder) {
this.profileForm = this.fb.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required],
email: ['', Validators.required],
mobileNo: ['', Validators.required]
});
}
than you have to import ReactiveFormsModule in app.module.ts file
import { ReactiveFormsModule } from '@angular/forms';
without ReactiveFormsModule formGroup not work it make error
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UserProfileComponent } from './user-profile.component';
import { UserProfileRoutingModule } from './user-profile-routing.module';
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
CommonModule,
UserProfileRoutingModule,
ReactiveFormsModule
],
declarations: [UserProfileComponent]
})