A
A
Artem00712017-02-03 21:35:43
Angular
Artem0071, 2017-02-03 21:35:43

How to pass parameter from service to component?

There is a service.
I pass an array of songs into it, at the end they change ({title:string, file:string}).
How can I pass to another component that the song has changed and its name?
Angular 2

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kostya Gorozhanov, 2017-02-03
@Artem0071

Look at https://makeomatic.ru/blog/2014/10/07/Angular_scop...

A
Alexander Belov, 2017-02-03
@AlexanderBelov

In the component class, you declare variables and track (subscribe) the change in the array with songs, something like this:

playing: string; //в рендере *ngFor="let track of tracks", например, {{track.playing}}
title: string; //в рендере *ngFor="let track of tracks", например, {{track.title}}


ngOnInit(){
  	this.songsService.getSongs().subscribe(
  		(data) => this.myTracks = data
  	);
  }

L
lega, 2017-02-03
@lega

How to pass an action from a service to a component?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question