import { Component } from '@angular/core'; import {Http, Headers} from '@angular/http'; import {map} from 'rxjs/operators'; import {ViewEncapsulation} from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css','../assets/css/materialize.min.css','../assets/css/fontawesome-all.min.css'], encapsulation: ViewEncapsulation.None }) export class AppComponent { title = 'ngx-tweets'; searchquery = ''; tweetsdata; constructor(private http: Http) {} makecall(){ //alert('hola mundo'); var headers = new Headers(); headers.append('content-Type', 'application/X-www-form-urlencoded'); this.http.post('http://localhost:3000/authorize',{headers:headers}).subscribe((res)=>{ console.log(res); }); } searchcall(){ this.makecall(); document.getElementById('tweets').style.display = 'block'; document.getElementById('buttonRecent').classList.add("active"); document.getElementById('buttonPopular').classList.remove("active"); var headers = new Headers(); var searchterm = 'query=#' + this.searchquery; headers.append('Content-Type', 'application/X-www-form-urlencoded'); this.http.post('http://localhost:3000/search', searchterm, {headers: headers}).subscribe((res) => { this.tweetsdata = res.json().data.statuses; }); } filterRecent(){ document.getElementById('buttonRecent').classList.add("active"); document.getElementById('buttonPopular').classList.remove("active"); var headers = new Headers(); var searchterm = 'query=#' + this.searchquery; headers.append('Content-Type', 'application/X-www-form-urlencoded'); this.http.post('http://localhost:3000/searchRecent', searchterm, {headers: headers}).subscribe((res) => { this.tweetsdata = res.json().data.statuses; }); } filterPopular(){ document.getElementById('buttonRecent').classList.remove("active"); document.getElementById('buttonPopular').classList.add("active"); var headers = new Headers(); var searchterm = 'query=#' + this.searchquery; headers.append('Content-Type', 'application/X-www-form-urlencoded'); this.http.post('http://localhost:3000/searchPopular', searchterm, {headers: headers}).subscribe((res) => { this.tweetsdata = res.json().data.statuses; }); } onKeydown(event) { if (event.key === "Enter") { this.searchcall(); } } usercall(){ var headers = new Headers(); var searchterm = 'screenname=Yasmin_Payne1'; headers.append('Content-Type', 'application/X-www-form-urlencoded'); this.http.post('http://localhost:3000/user', searchterm, {headers: headers}).subscribe((res) => { console.log(res.json().data); }); } }