Provide ContactService via a module
parent
c95734bb04
commit
6d19f3fe97
|
@ -5,11 +5,12 @@ import { AppComponent } from './app.component';
|
|||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { NameComponent } from './name/name.component';
|
||||
import { ContactModule } from '@nested-forms/contact';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [RouterTestingModule, ReactiveFormsModule],
|
||||
imports: [RouterTestingModule, ReactiveFormsModule, ContactModule.forRoot()],
|
||||
declarations: [AppComponent, NameComponent, AddressListComponent, AddressComponent]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { ContactService } from './../../../../libs/contact/src/lib/contact.service';
|
||||
import { Contact } from '@nested-forms/contact';
|
||||
import { Contact, ContactService } from '@nested-forms/contact';
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { FormGroup, FormBuilder } from '@angular/forms';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
|
|
@ -7,6 +7,7 @@ import { ReactiveFormsModule } from '@angular/forms';
|
|||
import { NameComponent } from './name/name.component';
|
||||
import { AddressListComponent } from './address-list/address-list.component';
|
||||
import { AddressComponent } from './address/address.component';
|
||||
import { ContactModule } from '@nested-forms/contact';
|
||||
|
||||
@NgModule({
|
||||
declarations: [AppComponent, NameComponent, AddressListComponent, AddressComponent],
|
||||
|
@ -14,6 +15,7 @@ import { AddressComponent } from './address/address.component';
|
|||
BrowserModule,
|
||||
RouterModule.forRoot([], { initialNavigation: 'enabled' }),
|
||||
ReactiveFormsModule,
|
||||
ContactModule.forRoot(),
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent]
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
export * from './lib/contact-model';
|
||||
export * from './lib/contact.service';
|
||||
export * from './lib/contact.module';
|
|
@ -0,0 +1,28 @@
|
|||
import { NgModule, Optional, SkipSelf } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ContactService } from './contact.service';
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
CommonModule
|
||||
]
|
||||
})
|
||||
export class ContactModule {
|
||||
constructor(
|
||||
@Optional()
|
||||
@SkipSelf()
|
||||
parentModule: ContactModule
|
||||
) {
|
||||
if (parentModule) {
|
||||
throw new Error('ContactModule is already loaded. Import it in the AppModule only');
|
||||
}
|
||||
}
|
||||
|
||||
static forRoot() {
|
||||
return {
|
||||
ngModule: ContactModule,
|
||||
providers: [ ContactService ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,9 +27,7 @@ const contact: Contact = {
|
|||
],
|
||||
};
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@Injectable()
|
||||
export class ContactService {
|
||||
constructor() { }
|
||||
|
||||
|
|
Loading…
Reference in New Issue