@angular/cli项目构建--httpClient
app.module.ts update
imports: [
HttpClientModule]
product.component.ts
import {Component, OnInit} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import * as _ from 'lodash';
@Component({
selector: 'app-product',
templateUrl: './product.component.html',
styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {
products: string[];
constructor(private http: HttpClient) {
}
ngOnInit() {
this.http.get('assets/json/product.json')
.subscribe(data => {
this.products = data['products'];
});
}
}
assets/json/product.json add
{
"products": [
{
"id": "1",
"name": "第一个商品",
"price": "899",
"rating": "3.5",
"desc": "苹果手机",
"category": "电子产品"
},
{
"id": "2",
"name": "第二个商品",
"price": "899",
"rating": "4",
"desc": "联想电脑",
"category": "电子产品"
}
]
}
@angular/cli项目构建--httpClient的更多相关文章
- @angular/cli项目构建--组件
环境:nodeJS,git,angular/cli npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm instal ...
- @angular/cli项目构建--modal
环境准备: cnpm install ngx-bootstrap-modal --save-dev impoerts: [BootstrapModalModule.forRoot({container ...
- @angular/cli项目构建--路由3
路由定位: modifyUser(user) { this.router.navigate(['/auction/users', user.id]); } 路由定义: {path: 'users/:i ...
- @angular/cli项目构建--Dynamic.Form
导入所需模块: ReactiveFormsModule DynamicFormComponent.html <div [formGroup]="form"> <l ...
- @angular/cli项目构建--animations
使用方法一(文件形式定义): animations.ts import { animate, AnimationEntryMetadata, state, style, transition, tri ...
- @angular/cli项目构建--interceptor
JWTInterceptor import {Injectable} from '@angular/core'; import {HttpEvent, HttpHandler, HttpInterce ...
- @angular/cli项目构建--路由2
app.module.ts update const routes: Routes = [ {path: '', redirectTo: '/home', pathMatch: 'full'}, {p ...
- @angular/cli项目构建--路由1
app.module.ts import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angu ...
- @angular/cli项目构建--Dynamic.Form(2)
form-item-control.service.ts update @Injectable() export class FormItemControlService { constructor( ...
随机推荐
- BDC程序步骤
(1)记录屏幕操作: (2)产生相关程序和数据格式文件: (3)调整数据文件: (4)运行BDC产生的程序读取文件导入数据: (5)源代码分析: (6)用BDC 导入单据: 在理解ABAP 开发的sc ...
- Spring boot cassandra - nested exception is com.datastax.driver.core.exceptions.NoHostAvailableException
1.在Pom.xml添加spring-boot-starter-data-cassandra依赖: <dependency> <groupId>org.springframew ...
- Spring Boot之AOP面向切面编程-实战篇
目录 前言 编程范式主要有以下几类 引入pom依赖 aop注解 实现日志分割功能 前言 AOP是一种与语言无关的程序思想.编程范式.项目业务逻辑中,将通用的模块以水平切割的方式进行分离统一处理,常用于 ...
- Groovy系列-groovy比起Java--有哪些地方写起来更舒服?
groovy比起java-有哪些地方写起来更舒服 java发展缓慢,语法落后冗余 说起java,其实java挺好的,java现在的性能也不错,但是,java的语法显然比较落后,而且冗余,getter/ ...
- Polar 投影c#版本移植
from:http://hi.baidu.com/sungaoyong/item/0c4584d25873f131e3108f05 ///刘泽军java版本的极坐标投影c#版本的移植 using Sy ...
- Android下拉快捷设置面板添加快捷开关流程
快速设定面板上快捷开关的加载流程,包括图标等的加载和点击事件等的处理过程,以及创建一个快捷开关的主要过程(以增加一个锁屏开关为例).本文所讨论的Android版本为5.1. 快捷开关的加载流程 资源模 ...
- iOS WKWebView OC 与 JS 交互学习
我写WKWebView 想让 服务端相应 一个 方法但是不响应,根据 UIWebView 用 JSContext就能拿到响应的处理经验是不是服务端 也需要 对 WKwebView有兼容的一个写法??? ...
- iOS CMTimeMake 和 CMTimeMakeWithSeconds 学习
CMTime是专门用于标识电影时间的结构体,通常用如下两个函数来创建CMTime (1)CMTimeMake CMTime CMTimeMake ( int64_t value, //表示 当前视频播 ...
- 根据GUID获取设备信息
#include <windows.h> #include <setupapi.h> #include <objbase.h> #include <initg ...
- 每天一个Linux命令(63)scp命令
scp(secure copy)用于进行远程文件拷贝. (1)用法: 用法: scp [参数] [源文件] [目标文件] (2)功能: 功能: scp在主机 ...