Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

videoTitle$ Angular 2 - communication between two sibling components

Because you are working with Observers and Observables in your service, 
you don't need to communicate both components because you can directly
 connect the service with the component template. This should be the code:

Service:

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Subject }    from 'rxjs/Subject';
import 'rxjs/add/operator/map';

@Injectable()
export class AppService {
  private apiURL = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails,status&maxResults=10&playlistId=PLSi28iDfECJPJYFA4wjlF5KUucFvc0qbQ&key=AIzaSyCuv_16onZRx3qHDStC-FUp__A6si-fStw&pretty=true";

  //Observable string sources
  private thisVideoTitle = new Subject<string>();
  //Observable string streams
  videoTitle$ = this.thisVideoTitle.asObservable();
  constructor(private http:Http) { }

  getData() {
    return this.http.get(this.apiURL)
      .map((res:Response)=> res.json())
      .subscribe(nameTitle => this.thisVideoTitle.next(nameTitle))
  }
}

part ii
Then if you want to use this into your component template it should be something like:
<li *ngFor="let title of videoTitle$ | async"></li>
Comment

PREVIOUS NEXT
Code Example
Javascript :: Entendendo Package Json e instalando o Express 
Javascript :: agora token Renewal 
Javascript :: remove falsy values from object lodash 
Javascript :: how to calculate number with arithmetic operators in javascript 
Javascript :: libfluidsynth npm 
Javascript :: how to combine all array element 
Javascript :: Chrome Extension get Selection 
Javascript :: https://social-network.samuraijs.com/article/faq_po_api 
Javascript :: javascript date now format yyyy-mm-dd hh24 mi ss 
Javascript :: how many times one element is reapete of an array in js 
Javascript :: convert var to string jquery 
Javascript :: how to draw and expression tree 
Javascript :: Mongoose make Object required 
Javascript :: leap year javascript 
Javascript :: indonesia whatsapp formatter javascript 
Javascript :: check if object is empty js 
Javascript :: javascript copy input value to clipboard on click 
Javascript :: Collision between two div vanillaJS no detection 
Javascript :: npm ERR! code EBADPLATFORM stylint 
Javascript :: Remove a class when the backspace-key is pressed inside the input field 
Javascript :: how to get the value of state of on and off 
Javascript :: react-tournament-ready 
Javascript :: add content in textarea by clicking on button 
Javascript :: regex expression for password uppercase lowercase specil character , number in js 
Javascript :: Iterating over a TypedArray 
Javascript :: build class component react 
Javascript :: rename data table button 
Javascript :: how create a random enum on postman variable 
Javascript :: how to change cursor color in vscode 
Javascript :: javascript random number between 10 and 100 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =