[Angular 2] Simple intro Http
2023-09-14 09:00:54 时间
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-datetime-picker 格式
- Angular和Vue.js 深度对比
- Go HTTP 编程 | 01 - 使用 http 包创建 Web 服务器
- Angular 里 HTTP 请求和响应结构的拦截器(interceptors)在 SAP Spartacus 中的应用
- 前端面试题angular_Vue前端面试题
- angular 路由懒加载_angular路由
- uat环境和生产环境的区别_angular 生产环境 相对路径无效
- 干货 | 一文搞懂在AlmaLinux上安装Angular JavaScript框架
- Angular 模块封装概念常见的错误理解
- 关于 Angular 工程文件 angular.json 里的 inlineCritical 属性
- 关于 Angular 应用的 Bootstrap 过程
- WordPress 教程:使用 WP_Http 在 WordPress 中发起 HTTP Request
- 备受 Vue、Angular 和 React 青睐的 Signals 演进史
- 服务 Linux下检测HTTP服务的方法(linux测试http)
- 服务Linux 下监控HTTP服务的方法(linux监控http)
- Linux下HTTP抓包实战精要(http抓包linux)
- Linux搭建HTTP代理实现网络自由访问(linux搭建http代理)
- HTTP请求在Linux下的实现(http请求linux)
- 一步之遥从HTTP访问Oracle数据库(http访问oracle)
- 熟悉Redis,HTTP抓包,防止网络安全漏洞(redis,http抓包)
- angular简介和其特点介绍