import { Component , View } from "angular2/core" ; import { ContactService } from "./contact.service" ; import { Router } from 'angular2/router' ; import { Contact } from './contact' ; @ Component ( { templateUrl : '../dev/contacts/newcontact.component.html' , providers : [ ContactService ] , styles : [ `
      .ng-invalid{
        border:1px solid red;
      }
    ` ] } ) export class NewContactComponent { newContact : Contact ; constructor ( private _contactService , private _router ) { this . newContact = { id : '' , firstname : '' , lastname : '' , email : '' } ; } onAddContact ( ) { this . newContact . id = Math . floor ( ( Math . random ( ) * 100 ) + 1 ) . toString ( ) ; console . log ( this . newContact ) ; this . _contactService . insertContact ( this . newContact ) ; this . _router . navigate ( [ 'Contacts' ] ) ; } }