跟着angularjs2官方文档学习(五)

2023-11-04



<!DOCTYPE html>
<html>
  <head>
    <title>Angular 2 Http Demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">

    <!-- IE required polyfills, in this exact order -->
    <script src="lib/es6-shim.min.js"></script>
    <script src="lib/system-polyfills.js"></script>
    <script src="lib/shims_for_IE.js"></script>

    <script src="lib/angular2-polyfills.js"></script>
    <script src="lib/system.js"></script>
    <script src="lib/typescript.js"></script>
    <script src="lib/Rx.js"></script>
    <script src="lib/angular2.dev.js"></script>

    <script src="lib/http.dev.js"></script>

    <script src="lib/web-api.js"></script>
    <script>
      System.config({
        transpiler: 'typescript', 
        typescriptOptions: { emitDecoratorMetadata: true }, 
        packages: {'app': {defaultExtension: 'ts'}} 
      });
      System.import('app/main')
            .then(null, console.error.bind(console));
    </script>

  </head>

  <body>
    <my-toh>ToH Loading...</my-toh>
  </body>

</html>


<!-- 
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->

import {bootstrap}         from 'angular2/platform/browser';

import 'rxjs/Rx';

import {TohComponent}         from './toh/toh.component';

bootstrap(TohComponent);

/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/


import {Component}         from 'angular2/core';
import {HTTP_PROVIDERS}    from 'angular2/http';

import {Hero}              from './hero';
import {HeroListComponent} from './hero-list.component';
import {HeroService}       from './hero.service';

import {provide}           from 'angular2/core';
import {XHRBackend}        from 'angular2/http';

// in-memory web api imports
import {InMemoryBackendService,
        SEED_DATA}         from 'a2-in-memory-web-api/core';
import {HeroData}          from '../hero-data';

@Component({
  selector: 'my-toh',
  template: `
  <hero-list></hero-list>
  `,
  directives:[HeroListComponent],
  providers: [
    HTTP_PROVIDERS,
    HeroService,
    provide(XHRBackend, { useClass: InMemoryBackendService }), // in-mem server
    provide(SEED_DATA,  { useClass: HeroData }) // in-mem server data
  ]
})
export class TohComponent { }


/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/

import {Component, OnInit} from 'angular2/core';
import {Hero}              from './hero';
import {HeroService}       from './hero.service';

@Component({
  selector: 'hero-list',
  template: `
  <h3>Heroes:</h3>
  <ul>
    <li *ngFor="#hero of heroes">
      {{ hero.name }}
    </li>
  </ul>
  New Hero:
  <input #newHero />
  <button (click)="addHero(newHero.value); newHero.value=''">
    Add Hero
  </button>
  <div class="error" *ngIf="errorMessage">{{errorMessage}}</div>
  `,
  styles: ['.error {color:red;}']
})
export class HeroListComponent implements OnInit {

  constructor (private _heroService: HeroService) {}

  errorMessage: string;
  heroes:Hero[];

  ngOnInit() { this.getHeroes(); }

  getHeroes() {
    this._heroService.getHeroes()
                     .subscribe(
                       heroes => this.heroes = heroes,
                       error =>  this.errorMessage = <any>error);
  }

  addHero (name: string) {
    if (!name) {return;}
    this._heroService.addHero(name)
                     .subscribe(
                       hero  => this.heroes.push(hero),
                       error =>  this.errorMessage = <any>error);
  }
}


/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/

import {Injectable}     from 'angular2/core';
import {Http, Response} from 'angular2/http';
import {Headers, RequestOptions} from 'angular2/http';
import {Hero}           from './hero';
import {Observable}     from 'rxjs/Observable';

@Injectable()
export class HeroService {
  constructor (private http: Http) {}

  /*
  private _heroesUrl = 'app/heroes.json'; // URL to JSON file
  */

  private _heroesUrl = 'app/heroes';  // URL to web api

  getHeroes () {
    return this.http.get(this._heroesUrl)
                    .map(res => <Hero[]> res.json().data)
                    .do(data => console.log(data)) // eyeball results in the console
                    .catch(this.handleError);
  }

  addHero (name: string) : Observable<Hero>  {

    let body = JSON.stringify({ name });
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });

    return this.http.post(this._heroesUrl, body, options)
                    .map(res =>  <Hero> res.json().data)
                    .catch(this.handleError)
  }

  private handleError (error: Response) {
    // in a real world app, we may send the error to some remote logging infrastructure
    // instead of just logging it to the console
    console.error(error);
    return Observable.throw(error.json().error || 'Server error');
  }
}


/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/

export class Hero {
  constructor(
    public id:number,
    public name:string) { }
}


/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/

export class HeroData {
  createDb() {
    let heroes = [
      { "id": "1", "name": "Windstorm" },
      { "id": "2", "name": "Bombasto" },
      { "id": "3", "name": "Magneta" },
      { "id": "4", "name": "Tornado" }
    ];
    return {heroes};
  }
}


/*
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
{
  "data": [
    { "id": "1", "name": "Windstorm" },
    { "id": "2", "name": "Bombasto" },
    { "id": "3", "name": "Magneta" },
    { "id": "4", "name": "Tornado" }
  ]
}



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

跟着angularjs2官方文档学习(五) 的相关文章

  • S3C2440读写sd卡的一些总结

    整理硬盘的时候发现这个文档 以前写2440操作sd卡程序的时候总结的 1 我的2440 sdi对sd卡发送ACMD41时总是反馈crc fail 但是可以得到正确的response sd卡可以正常使用 2 sd卡可以没有mbr 在物理的 0
  • 推理规则的具体应用

    小伙伴们 大家好呀 相信步入大二的同学们肯定会学到离散数学 而推理规则是离散数学中最fundmental and important 的知识体系 今天我们来说说基本的推理规则 Firstly 推理 inference rules 是 前提
  • hibernate--lazy(懒加载)属性

    关联映射文件中
  • 线性表之单链表

    include stdafx h include
  • WebRTC学习(二)Windows10平台WebRTC编译(VS2017)

    1 Visual Studio 2017安装 WebRTC用到了很多C 最新特性 所以编译最新WebRTC代码VS要求为2017 gt 15 7 2 版本 2 安装SDK调试工具 由于最新WebRTC源码要求10 0 18362及以上Win
  • wordpress线上部署&更新主题

    目录 新增主题 主题介绍 部署到线上 更新主题 新增主题 随便复制一个主题到test文件夹 test主题文件cnpm I npm i 失败的可以使用淘宝镜像 cpm i 热更新 主题介绍 test目录下的style css Theme Na
  • 论文笔记:LightGCL: Simple Yet Effective Graph Contrastive Learning for Recommendation

    ICLR 2023 1 intro GNN在基于图的推荐系统中展现了良好的效果 这得益于其整合相邻结点信息以进行协同过滤的能力 在用户 物品交互图上进行多层的信息传递 以此挖掘高阶的连接信息 很大一部分基于 GNN 的协同过滤模型采用了监督
  • vue跨域处理(vue项目中baseUrl设置问题)

    一 方法一 在公用文件common js中设置baseUrl export var baseUrl process env NODE ENV production window g ApiUrl api 该方法的优点 在项目打包时 stat
  • jvm关闭

    关闭方式 正常关闭 最后一个普通线程 非守护线程 结束 调用了System exit 发送SIGINT信号 相当于不带参数的kill命令 或者键入Ctrl C 强制关闭 调用Runtime halt 发送SIGKILL信号 kill 9 命
  • 认证鉴权与API权限控制在微服务架构中的设计与实现(一)

    引言 本文系 认证鉴权与API权限控制在微服务架构中的设计与实现 系列的第一篇 本系列预计四篇文章讲解微服务下的认证鉴权与API权限控制的实现 1 背景 最近在做权限相关服务的开发 在系统微服务化后 原有的单体应用是基于Session的安全
  • JavaScript中的backgroundPosition的设置

    在CSS中background position有对值的设置有两种 一是用数值 绝对的 另一个使用百分比 相对的 这两种方式会有不同的浏览器兼容问题 主要是IE和FF 基本代码如下 style overflow y scroll heigh
  • 从RPA+AI到IPA,RPA是如何进化的?

    随着RPA 机器人流程自动化 的深入发展 如今对于该技术今后的走向业内也形成了共识 那就是RPA不能 独行 一定要加个 伴儿 至于加 谁 则见仁见智 比较常见的则是加AI 人工智能 RPA AI 其实并不是件新鲜事 我们将时间拨回到5年前
  • Windbg分析高内存占用问题

    打Dump 远程客户应用服务器 32G内存占用已经消耗了78 而现场已经反馈收银系统接近奔溃了 要求先强制回收内存 反正也要奔溃了 先打Dump再说吧 PS 打Dump会挂起进程 导致应用无法响应 而打Dump的耗时 也是根据当时进程的内存

随机推荐

  • 循环打印数字文件名

    循环打印以顺序数字为标识 且格式为 0 的文件名 for s in range 10 a f train id s 03 tif print a train004 tif train005 tif train006 tif train007
  • 基于接口设计原则-java

    7种设计坏味道 1 僵化性 很难对系统进行改动 因为每个改动都会迫使许多对系统其他部分的其它改动 2 脆弱性 对系统的改动会导致系统中和改动的地方在概念上无关的许多地方出现问题 3 牢固性 很难解开系统的纠结 使之成为一些可在其他系统中重用
  • PyTorch中squeeze()和unsqueeze()函数理解

    squeeze arg 表示若第arg维的维度值为1 则去掉该维度 否则tensor不变 即若tensor shape arg 1 则去掉该维度 例如 一个维度为2x1x2x1x2的tensor 不用去想它长什么样儿 squeeze 0 就
  • 小程序:TypeError: Cannot read property ‘restore‘ of undefined

    去看了一些文字说肯能是data里面定义了 restore 而且还是引用类型 数据没有出来就渲染了也就导致了报错undefind 但是自己去看了一些data里面没有定义 restore 也是看了许久的文章才发现一篇文章说是 小程序的版本要降低
  • 笔试

    文章目录 前言 39 跨时钟域问题 1 从亚稳态入手 2 跨时钟域传输的几种情况 3 单bit信号的跨时钟域传输 3 1单bit信号从慢时钟域到快时钟域传输 3 2单bit信号从快时钟域到慢时钟域传输 脉冲同步器 窄脉冲捕捉电路 下期预告
  • 缓动 css,[CSS3] CSS缓动曲线整理

    常用效果 easeInSine cubic bezier 0 47 0 0 745 0 715 easeOutSine cubic bezier 0 39 0 575 0 565 1 easeInOutSine cubic bezier 0
  • SD卡SPI模式 读写block

    声明 第一次写教程 如若有错误 请指出更正 看了很多网上的教程 还是觉得很多教程中 写多个块的时候有些问题 因此经过3天的奋斗 写出自己的教程 本教程中 没有挂载文件系统 单纯读写Block 会破坏分区和数据 下节再 装上文件系统Fatfs
  • Html5监听返回事件

    常使用的场景 移动前端 1 安卓手机物理返回键 2 苹果手机在企业微信打开浏览器的返回按钮 移动前端开发语言是 vue 路由跳转 vue router hash模式 先介绍一下html5中history有哪些属性和API 我们用到了其中2个
  • Pcl粗配准矩阵不唯一

    经过一段时间的调试 发现转换矩阵不唯一 因此要将两个点云的数值减去一个值 使之最小 受到矩阵相乘相加受到的影响最小
  • 继承:父类和子类的关系

    继承 父类和子类的关系 一 父类引用指向子类对象时 1 若子类覆盖了某方法 则父类引用调用子类重新定义的新方法 2 若子类未覆盖某方法 则父类引用调用父类本身的旧方法 3 若子类覆盖了某属性 但父类引用仍调用父类本身的旧属性 4 若子类未覆
  • Linux命令后台运行

    Linux后台运行命令有两种方式 cmd 后台运行 关掉终端会停止运行 nohup cmd 后台运行 关掉终端不会停止运行 方式一 cmd cmd 实现让命令在后台运行 但不要将有用户交互的命令放到后台 这样命令会在后台等待用户输入 后台运
  • [leetcode160]

    Definition for singly linked list class ListNode object def init self x self val x self next None class Solution object
  • 用ChatGPT后被海外名校录取,泰库啦!!

    世界之大无奇不有 有人竟然因为使用ChatGPT后被海外大学录取 ChatGPT真的那么强大吗 竟然有这样子的能力 国内一些朋友因为各种问题没有办法使用ChatGPT 文章后面会给大家分享国内ChatGPT免注册免费使用的方法教程 今天一看
  • web安全的常用靶场

    文章目录 1 sqlmap 2 Test Lab 方便测试 列出以下WEB的靶场 仅供参考 1 sqlmap 0 作者出的漏洞测试环境 sqlmap 1 owasp 2 owaspbwa 3 xvwa 4 webgoad 5 DVWA 6
  • ananconda添加镜像

    先执行 conda config set show channel urls yes 生成该文件之后再修改 在用户目录下的 修改 condarc 文件 channels defaults show channel urls true cha
  • 联想小新air14安装ubuntu16.04

    首先正常安装 会遇到显卡问题 进入ubuntu高级模式 recovery mode resume 然后按照这篇教程整 https blog csdn net Guangli R article details 86636923 utm so
  • PCB设计 接地 铺铜的技巧

    PCB设计 接地 铺铜的技巧 1 PCB设计接地敷铜的技巧 pcb 电工之家 2 覆铜步骤及设计规则 百度文库 3 产品可靠性1 多层电路板应不应该在顶层和底层铺铜 Steven Aileen的博客 CSDN博客 4层板顶底层还用铺铜吗
  • 淘宝、支付宝菜鸟小程序取件码找不到的解决方法

    淘宝 支付宝菜鸟小程序身份码找不到的解决方法 今天拿快递的时候在淘宝里面找身份码 死活找不到 明明之前可以找到的 最后还是下载了菜鸟裹裹app才能取件 上网搜索了一下 发现有的地方很早就把小程序里面的身份码给阉割了 强行让用户下载app实属
  • Evaluate Video Quality

    How to evaluate video PSNR and SSIM PSNR is easy to calculate http blog csdn net c602273091 article details 49861817 SSI
  • 跟着angularjs2官方文档学习(五)