Skip to content

Instantly share code, notes, and snippets.

@Dornhoth
Last active September 11, 2020 15:37
Show Gist options
  • Save Dornhoth/52ee78eba6a69a7dc60dbc1e04e63e29 to your computer and use it in GitHub Desktop.
Save Dornhoth/52ee78eba6a69a7dc60dbc1e04e63e29 to your computer and use it in GitHub Desktop.
Service Injection
import { Component, OnInit } from '@angular/core';
import { TestService } from 'src/app/services/test.service';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
})
export class TestComponent implements OnInit {
text: string;
constructor(
private testService: TestService, // the DI makes sure you get an instance
) { }
ngOnInit() {
this.text = this.testService.getTest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment