To use http, we need to import the HTTP_PROVIDER, so that we can inject http to other component:

import {HTTP_PROVIDERS} from 'angular2/http';

bootstrap(App, [
HTTP_PROVIDERS
]);

simple-request.ts:

import {Component} from 'angular2/core';
import {Http, Response} from 'angular2/http';
@Component({
selector: 'simple-request',
template: `
<button type="button" (click)="makeRequest()">Make Request</button>
<div *ngIf="loading">loading...</div>
<pre>{{data | json}}</pre>
`
}) export class SimpleRequest{
loading: boolean = false;
data: Object;
constructor(public http: Http){ } makeRequest(){
this.loading = true;
this.http.request('https://api.github.com/users/zhentian-wan')
.subscribe( (res: Response) => {
this.data = res.json();
this.loading = false;
})
}
}

[Angular 2] Simple intro Http的更多相关文章

  1. [Angular 2] Directive intro and exportAs

    First, What is directive, what is the difference between component and directive. For my understandi ...

  2. Angular源代码学习笔记-原创

    时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...

  3. angular 接入 IdentityServer4

    angular 接入 IdentityServer4 Intro 最近把活动室预约的项目做了一个升级,预约活动室需要登录才能预约,并用 IdentityServer4 做了一个统一的登录注册中心,这样 ...

  4. Angularjs 源码

    /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http://angularjs.org function t ...

  5. Hello Ragel -- 生成状态机的神器

    Ragel 是个很 NB 的能生成状态机的编译器,而且支持一堆语言:C.C++.Object-C.C#.D.Java.Go 以及 Ruby. 原来的文本解析器是用正则表达式实现的,随着状态(if-el ...

  6. [Angular 2] Create a simple search Pipe

    This lesson shows you how to create a component and pass its properties as it updates into a Pipe to ...

  7. [Angular 2] A Simple Form in Angular 2

    When you create a Form in Angular 2, you can easily get all the values from the Form using ControlGr ...

  8. [Angular] Angular Elements Intro

    Make sure install the latest Angular v6 with Angular CLI. Checkout ght Github for the code. 1. Creat ...

  9. [Angular] Angular CDK Intro

    1. Installl latest @angular/cli: sudo npm i -g @angular/cli@next The version I used is:6.0.0-rc.10 2 ...

随机推荐

  1. solr单机版的搭建

    一.solr单机版的搭建 1.运行环境 solr 需要运行在一个Servlet容器中,Solr4.10.3要求jdk使用1.7以上,Solr默认提供Jetty(ja),本教va写的Servlet容器程 ...

  2. Jenkins学习之——(4)Email Extension Plugin插件的配置与使用

    1.先安装插件 2.配置 点击高级后 内容配置: 3.项目配置 点击Advanced Settings后 到此所有的配置都设置完成. 附录: 以下内容来自其他网友的博客,内容也没有自己去试,朋友们可以 ...

  3. C++ for 循环

    C++的另一种for循环写法,和C#的foreach语法很类似,不需要知道数组的类型: C++:for(auto& item:items) C#:foreach(var item in ite ...

  4. jquery网站左侧弹出导航菜单

    下载

  5. 开发ContentProvider的步骤

    开发ContentProvider的步骤如下: 1.编写一个类,该类必须继承自ContentProvider. 2.实现ContentProvider类中的所有抽象方法:insert() delete ...

  6. spring boot了解

    spring4倾向于基于注解的配置,强化的注解的功能,对比与spring3还是有很多的区别:spring boot对spring的各个组件功能管理,基于默认配置即可简单构建一个spring4的项目,对 ...

  7. 在windows下搭建linux-c学习环境

    下载virtualbox并安装: https://www.virtualbox.org/wiki/Downloads 现在vagrant并安装: https://www.vagrantup.com/d ...

  8. macbook air 安装win7系统时,到最后一步要进入win7,需要给PC设置一个用户名,键盘没反应

    从 bootcamp安装:1.一定要同时选中第一项 制作usb安装盘和第二项 从网上下载最新的windows支持软件,2.然后再选第三项 安装winDows,3.当进入安装界面时选择你要安装的boot ...

  9. 使用开源word操作组件DocX的记录

    1.DocX简介 1.1 简介 DocX是一个在不需要安装word的情况下对word进行操作的开源轻量级.net组件,是由爱尔兰的一个叫Cathal Coffey的博士生开发出来的.DocX使得操作w ...

  10. 一个读取propeties配置文件的工具类,线程安全的

    public class ConfigUtil { private static Map<String,Properties> map = new HashMap<String,Pr ...