import { Injectable } from '@angular/core';@Injectable()export class LoggerServiceService { constructor() { } log(message: string) { console.log(message); }}
import { Injectable } from '@angular/core';import { LoggerServiceService } from './logger-service.service';@Injectable()export class ProductServiceService { constructor(private logger: LoggerServiceService) { } getProduct(): Product { this.logger.log("iPhone7"); return new Product(1, "iPhone7"); }}export class Product { constructor( public id: number, public title: string ) { }}
import { BrowserModule } from '@angular/platform-browser';import { NgModule } from '@angular/core';import { AppComponent } from './app.component';import { Product1Component } from './product1/product1.component';import { ProductServiceService } from './shared/product-service.service';import { Product2Component } from './product2/product2.component';import { LoggerServiceService } from './shared/logger-service.service';@NgModule({ declarations: [ AppComponent, Product1Component, Product2Component ], imports: [ BrowserModule ], providers: [ProductServiceService,LoggerServiceService], bootstrap: [AppComponent]})export class AppModule { }