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的更多相关文章

  1. @angular/cli项目构建--组件

    环境:nodeJS,git,angular/cli npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm instal ...

  2. @angular/cli项目构建--modal

    环境准备: cnpm install ngx-bootstrap-modal --save-dev impoerts: [BootstrapModalModule.forRoot({container ...

  3. @angular/cli项目构建--路由3

    路由定位: modifyUser(user) { this.router.navigate(['/auction/users', user.id]); } 路由定义: {path: 'users/:i ...

  4. @angular/cli项目构建--Dynamic.Form

    导入所需模块: ReactiveFormsModule DynamicFormComponent.html <div [formGroup]="form"> <l ...

  5. @angular/cli项目构建--animations

    使用方法一(文件形式定义): animations.ts import { animate, AnimationEntryMetadata, state, style, transition, tri ...

  6. @angular/cli项目构建--interceptor

    JWTInterceptor import {Injectable} from '@angular/core'; import {HttpEvent, HttpHandler, HttpInterce ...

  7. @angular/cli项目构建--路由2

    app.module.ts update const routes: Routes = [ {path: '', redirectTo: '/home', pathMatch: 'full'}, {p ...

  8. @angular/cli项目构建--路由1

    app.module.ts import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angu ...

  9. @angular/cli项目构建--Dynamic.Form(2)

    form-item-control.service.ts update @Injectable() export class FormItemControlService { constructor( ...

随机推荐

  1. Inception 2.0

    文章<Rethinking the Inception Architecture for Computer Vision> 介绍 VGG与GoogLeNet相比更朴素,但计算量大.Goog ...

  2. zabbix-2.4.8-1添加MySQL主从状态监控

    1.安装zabbix-agentyum -y install zabbix-2.4.8-1.el6.x86_64.rpm zabbix-agent-2.4.8-1.el6.x86_64.rpm 安装以 ...

  3. django-admin引用百度地图

    实现的功能有,某个地点对应的经纬度自动填上,如果有经纬度的话,自动显示对应经纬度的地点,密匙在去百度地图引用搜索 <script type="text/javascript" ...

  4. java eclipse 监视选择指定变量

    http://3y.uu456.com/bp_8tzmk3zobb7k6x46aj28_1.html 有时一个Java程序有许多变量,但你仅对其中一个或几个感兴趣,为了监视选择的变量和表达式,你可以将 ...

  5. 使用ajax进行汽车详情表的查询

    主界面代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  6. LDA主题模型三连击-入门/理论/代码

    目录 概况 为什么需要 LDA是什么 LDA的应用 gensim应用 数学原理 预备知识 抽取模型 样本生成 代码编写 本文将从三个方面介绍LDA主题模型--整体概况.数学推导.动手实现. 关于LDA ...

  7. Swift中字典解析后的问题,!?两种拆包的差别

    给出一个json,使用SwiftyJSON解析传给model,传进去是个字典,字典里有String,NSNumber,NSDoctionary,和NSArray. 正常情况下直接使用下面的解析方法即可 ...

  8. Spring session共享(使用redis)

    SpringBoot+Redis实现HttpSession共享 前提:需要使用redis做session存储 一.效果演练(这里使用SpringBoot工程,Spring同理) 1.一个工程使用两个端 ...

  9. Linux Shell编程 sort、wc命令

    sort命令:字符串排序 sort 命令可以依据不同的数据类型来进行排序.sort 将文件的每一行作为一个单位,相互比较.比较原则是从首字符向后,依次按 ASCII 码值进行比较,最后将它们按升序输出 ...

  10. 基于R语言的数据分析和挖掘方法总结——均值检验

    2.1 单组样本均值t检验(One-sample t-test) 2.1.1 方法简介 t检验,又称学生t(student t)检验,是由英国统计学家戈斯特(William Sealy Gosset, ...