Skip to content

Instantly share code, notes, and snippets.

@TimDorand
Created November 24, 2016 11:51
Show Gist options
  • Save TimDorand/fa588631347a0e1c4e38f3d6562b667f to your computer and use it in GitHub Desktop.
Save TimDorand/fa588631347a0e1c4e38f3d6562b667f to your computer and use it in GitHub Desktop.
import {Response} from '@angular/http';
import { HttpService } from './httpservice.service';
@Component({
selector: 'http-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers:[HttpService]
})
export class AppComponent implements OnInit {
items:any[];
title = 'http works!';
constructor(private httpservice:HttpService){
}
ngOnInit(){
this.httpservice.getData()
.subscribe(
(data:any) => console.log(data)
);
}
onSubmit(username:string,email:string){
this.httpservice.sendData({username:username,email:email})
.subscribe(
(data:any) => console.log(data)
);
}
onGetdata(){
this.httpservice.getMydata()
.subscribe(
data => {
const array = [];
for(let key in data){
array.push(data[key]);
}
this.items=array;
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment