EDIT - DO NOT DO IT -
@echonax, , , . , , - . , angular2 , .
END EDIT
, . , AppModule, . . plunkr , , .
SharedModule, angular2 doc.
https://angular.io/docs/ts/latest/guide/ngmodule.html#!#shared-module
plunkr.
https://plnkr.co/edit/SU8AT4
import { NgModule } from '@angular/core';
import { TestService } from './test.service';
@NgModule({
imports: [],
declarations: [],
providers: [
TestService
],
exports: [ ]
})
export class SharedModule { }
AppModule
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { TestComponent } from './test.component';
import { SharedModule } from './shared.module';
import { AppRoutingModule } from './app-routing.module';
@NgModule({
imports: [
BrowserModule,
AppRoutingModule,
SharedModule
],
declarations: [
AppComponent,
TestComponent
],
providers: [ ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
AppRoutingModule
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TestComponent } from './test.component';
import { SharedModule } from './shared.module';
const appRoutes: Routes = [
{ path: '', redirectTo: 'test', pathMatch: 'full' },
{ path: 'test', component: TestComponent },
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes),
SharedModule
],
exports: [ RouterModule ],
providers: []
})
export class AppRoutingModule { }