ng generate service app
Let's generate a service
import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class AppService { ... }
@Injectable
import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class AppService { private videos = []; getVideos(): any[] { return this.videos; } }
import { Component, OnInit } from '@angular/core'; import { AppService } from '../app.service'; @Component({ ... }) export class VideosComponent implements OnInit { videos: any[] = []; constructor(private appService: AppService) { } ngOnInit() { this.videos = this.appService.getVideos(); } }
@Component
By Konstantin Malikov
Angular & .net developer. Participating in growing Angular Community. Sharing knowledges. https://www.linkedin.com/in/konstantin-malikov-56b1681a2/