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

2023-11-05


<!DOCTYPE html>
<html>
<head>
  <!-- Set the base href -->
  <script>document.write('<base href="' + document.location + '" />');</script>

  <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>

  <!-- Add the router library -->
  <script src="lib/router.dev.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-app>loading...</my-app>
</body>

</html>

</html>

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

import {AppComponent}     from './app';

// Add these symbols to override the `LocationStrategy`
//import {provide}           from 'angular2/core';
//import {LocationStrategy,
//        HashLocationStrategy} from 'angular2/router';

bootstrap(AppComponent, [ROUTER_PROVIDERS,
    //provide(LocationStrategy,
    //       {useClass: HashLocationStrategy}) // .../#/crisis-center/
]);


/*
 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 {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';

import {HeroListComponent}     from './heroes/hero-list.component';
import {HeroDetailComponent}   from './heroes/hero-detail.component';
import {HeroService}           from './heroes/hero.service';

@Component({
    selector: 'my-app',
    template: `
    <nav>
      <a [routerLink]="['Heroes']">Heroes</a>
    </nav>
    <router-outlet></router-outlet>
  `,
    providers:  [ HeroService],
    directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
    {path: '/heroes',   name: 'Heroes',     component: HeroListComponent},
    {path: '/hero/:id', name: 'HeroDetail', component: HeroDetailComponent},
])
export class AppComponent { }

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

@Component({
  template: `
    <ul class="items">
      <li *ngFor="#hero of heroes"
        [class.selected]="isSelected(hero)"
        (click)="onSelect(hero)">
        <span class="badge">{{hero.id}}</span> {{hero.name}}
      </li>
    </ul>
  `
})
export class HeroListComponent implements OnInit {
  heroes: Hero[];

  private _selectedId: number;

  constructor(
    private _service: HeroService,
    private _router: Router,
    routeParams: RouteParams)
  {
      this._selectedId = +routeParams.get('id');
  }

  isSelected(hero: Hero) { return hero.id === this._selectedId; }

  onSelect(hero: Hero) {
    this._router.navigate( ['HeroDetail', { id: hero.id }] );
  }

  ngOnInit() {
    this._service.getHeroes().then(heroes => this.heroes = heroes)
  }
}

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

@Component({
  template: `
  <div *ngIf="hero">
    <h3>"{{hero.name}}"</h3>
    <div>
      <label>Id: </label>{{hero.id}}</div>
    <div>
      <label>Name: </label>
      <input [(ngModel)]="hero.name" placeholder="name"/>
    </div>
    <p>
      <button (click)="gotoHeroes()">Back</button>
    </p>
  </div>
  `,
})
export class HeroDetailComponent implements OnInit  {
  hero: Hero;

  constructor(
    private _router:Router,
    private _routeParams:RouteParams,
    private _service:HeroService){}

  ngOnInit() {
    let id = this._routeParams.get('id');
    this._service.getHero(id).then(hero => this.hero = hero);
  }

  gotoHeroes() {
    let heroId = this.hero ? this.hero.id : null;
    this._router.navigate(['Heroes',  {id: heroId} ]);
  }
}

import {Injectable} from 'angular2/core';

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

@Injectable()
export class HeroService {
  getHeroes() { return heroesPromise; }

  getHero(id: number | string) {
    return heroesPromise
      .then(heroes => heroes.filter(h => h.id === +id)[0]);
  }
}

var HEROES = [
	new Hero(11, 'Mr. Nice'),
	new Hero(12, 'Narco'),
	new Hero(13, 'Bombasto'),
	new Hero(14, 'Celeritas'),
	new Hero(15, 'Magneta'),
	new Hero(16, 'RubberMan')
];

var heroesPromise = Promise.resolve(HEROES);

/* Master Styles */
h1 {
  color: #369; 
  font-family: Arial, Helvetica, sans-serif;   
  font-size: 250%;
}
h2, h3 { 
  color: #444;
  font-family: Arial, Helvetica, sans-serif;   
  font-weight: lighter;
}
body { 
  margin: 2em; 
}
body, input[text], button { 
  color: #888; 
  font-family: Cambria, Georgia; 
}
a {
  cursor: pointer;
  cursor: hand;
}
button {
  font-family: Arial;
  background-color: #eee;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  cursor: hand;
}
button:hover {
  background-color: #cfd8dc;
}
button:disabled {
  background-color: #eee;
  color: #aaa; 
  cursor: auto;
}

/* Navigation link styles */
nav a {
  padding: 5px 10px;
  text-decoration: none;
  margin-top: 10px;
  display: inline-block;
  background-color: #eee;
  border-radius: 4px;
}
nav a:visited, a:link {
  color: #607D8B;
}
nav a:hover {
  color: #039be5;
  background-color: #CFD8DC;
}
nav a.router-link-active {
  color: #039be5;
}

/* items class */
.items {
  margin: 0 0 2em 0;
  list-style-type: none;
  padding: 0;
  width: 24em;
}
.items li {
  cursor: pointer;
  position: relative;
  left: 0;
  background-color: #EEE;
  margin: .5em;
  padding: .3em 0;
  height: 1.6em;
  border-radius: 4px;
}
.items li:hover {
  color: #607D8B;
  background-color: #DDD;
  left: .1em;
}
.items li.selected:hover {
  background-color: #BBD8DC;
  color: white;
}
.items .text {
  position: relative;
  top: -3px;
}
.items {
  margin: 0 0 2em 0;
  list-style-type: none;
  padding: 0;
  width: 24em;
}
.items li {
  cursor: pointer;
  position: relative;
  left: 0;
  background-color: #EEE;
  margin: .5em;
  padding: .3em 0;
  height: 1.6em;
  border-radius: 4px;
}
.items li:hover {
  color: #607D8B;
  background-color: #DDD;
  left: .1em;
}
.items li.selected {
  background-color: #CFD8DC;
  color: white;
}

.items li.selected:hover {
  background-color: #BBD8DC;
}
.items .text {
  position: relative;
  top: -3px;
}
.items .badge {
  display: inline-block;
  font-size: small;
  color: white;
  padding: 0.8em 0.7em 0 0.7em;
  background-color: #607D8B;
  line-height: 1em;
  position: relative;
  left: -1px;
  top: -4px;
  height: 1.8em;
  margin-right: .8em;
  border-radius: 4px 0 0 4px;
}

/* everywhere else */
* { 
  font-family: Arial, Helvetica, sans-serif; 
}


/*
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
*/



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

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

  • 小程序逆向工程:这个开源的小程序逆向工具真不错,2023年亲测成功

    前言 安全部门的大哥又双叒叕报了一个小程序的高危漏洞 他使用逆向工程破解了加密信心 用抓包修改了请求参数 又是头疼的一天 想成为一名微信小程序的开发者 前端思路的学习和安全意识是非常有必要的 故务必掌握小程序反编译技能 这里用到了2个工具
  • 虚拟化KVM

    什么是虚拟化 在计算机技术中 虚拟化是一种资源管理技术 是将计算机的各种实体资源 CPU 内存 磁盘空间 网络适配器等 予以抽象 转换后呈现出来并可供分割 组合为一个或多个计算机配置环境 并重新分割 重新组合 已达到最大化合理利用物理资源的
  • 程序的运行结构

    一 程序的运行结构有三种 1 顺序结构 2 分支结构 3 循环结构 二 分支结构 根据代码的成立与否 选择执行方向 包括 if 判断条件 代码块 if else语句 一定会执行一个语句或者是if里面的 或者是else里面的 switch 整
  • Leetcode每日一题:589. N 叉树的前序遍历

    前序遍历二叉树的要点就是根左右 在这里遍历的是n叉树 因此先访问根节点 然后再遍历根节点的每个孩子就可以了 递归解法 Definition for a Node class Node def init self val None child
  • Qt学习笔记:2018年8月记录

    1 Qt 设置背景图片注意事项 使用stylesheet设置背景图片还是有一些要注意的 如果是在mainwindow和dialog中 直接右键change style sheet在add resource中选择background imag
  • The method getContextPath() from the type HttpServletRequest refers to the missing type

    问题描述 每个JSP页面中的 request getContextPath 下方出现了红色的波浪线 提示的错误信息是 The method getContextPath from the type HttpServletRequest re
  • 微信小程序页面监听右上角退出,判断小程序进入后台时就实现页面跳转

    功能需求 在小程序中某一个页面没有进入后台的功能 如果点击右上角退出按钮 默认小程序进入后台 点击再次进入本页面 但是因为功能需要 在小程序进入后台时 再次进入需要跳转到首页 实现方法 在app js onHide 生命周期中监听进入后台的
  • 项目启动报错: This is very likely to create a memory leak. Stack trace of thread 解决方案

    问题发现 The web application ROOT appears to have started a thread named UIC STATISTIC THREAD but has failed to stop it This
  • 深度学习AI编译器-LLVM简介

    1 什么是LLVM LLVM的命名最早来源于底层语言虚拟机 Low Level Virtual Machine 的缩写 它是一个用于建立编译器的基础框架 以C 编写 创建此工程的目的是对于任意的编程语言 利用该基础框架 构建一个包括编译时
  • STM32 进阶教程 5 - 内联函数

    前言 在计算机科学中 内联函数 有时称作在线函数或编译时期展开函数 是一种编程语言结构 用来建议编译器对一些特殊函数进行内联扩展 有时称作在线扩展 也就是说建议编译器将指定的函数体插入并取代每一处调用该函数的地方 上下文 从而节省了每次调用
  • 用matlab生成规定维度的随机不重复矩阵

    这几天用到一个小功能 要生成随机不重复的整数矩阵 而且要求行和列数 写了个很好用的函数 分享一下 先上效果 以1为下界 10为上界 生成5行1列的随机矩阵s 以10为下界 100为上界 生成5行3列的随机矩阵s 想要直接用的可以去我资源界面
  • 天龙八部网单服务器修改爆率,【天龙八部3】网单一键安装服务端+GM工具+GM刷装备+视频教程 电脑单机版游戏...

    天龙八部3 网单一键安装服务端 GM工具 GM刷装备 视频教程 电脑单机版游戏 资源介绍 支持系统 WINXP WIN7 WIN8 WIN10 32 64位 支持网络 单机 次更新后为正常开出宝宝 繁殖为单人繁殖 修改宝宝为打满12技能 还
  • 基于yolov5的火焰识别

    基于yolov5的火焰识别 1 准备工作 yolov5项目下载 下载yolov5项目代码 其链接为 yolov5项目地址 并且在PC机上配置环境 即正常按照requirements安装依赖包 而后根据自身需要下载相应的权重文件 yolov5

随机推荐

  • 如何查看和修改Windows远程桌面端口

    如何查看和修改Windows远程桌面端口 一 查看Windows远程桌面端口 1 查看远程桌面服务TermService进程PID 选择 开始 gt 运行 输入 cmd 打开命令行窗口 执行 tasklist svc find Ter 如果
  • ununtu HI3559A学习笔记

    刚装上ubuntu18 04没有为wifi适配器 原因 没有驱动 网卡mediatek mt7630e 解决 来源 https blog csdn net zw chen article details 78355047 内容 Mediat
  • 全面了解一致性哈希算法及PHP代码实现

    在设计一个分布式系统的架构时 为了提高系统的负载能力 需要把不同的数据分发到不同的服务节点上 因此这里就需要一种分发的机制 其实就是一种算法 来实现这种功能 这里我们就用到了Consistent Hashing算法 在正式介绍Consist
  • 开发者,为什么需要构建知识图谱

    作者简介 安晓辉 10多年开发经验 曾任软件开发工程师 项目经理 研发经理 技术总监等岗位 著有 Qt Quick核心编程 Qt on Android核心编程 你好哇 程序员 等书籍 斜杠青年 技术专家 职业规划师 图书作者 在行西安首批行
  • Set集合转为List集合常见的方式

    将 Set 转为 List 可以有多种方法 以下是两种常见的实现方式 使用构造方法 可以使用 List 的构造方法 ArrayList Collection
  • 使用matlab通过遗传算法实现多元函数极值计算

    这里是对一个二元函数求解极大值问题 如果你希望求解更多元函数 需要添加额外的基因 例如z 在pop数组中添加第三列 染色体的第三列基因 设置新的评判标准函数 fitness 如果你希望提高运算精度 可以尝试增大种群规模 优秀基因出现概率更高
  • flowable(四) - 使用flowable-modeler-ui 定义流程

    步骤 地址 Flowable Modeler http localhost 8080 flowable modeler Flowable Task http localhost 8080 flowable task Flowable Adm
  • 使用Pytorch DataLoader快捷封装训练数据、测试数据的X与Y

    DataSet的用法可以参考 pytorch 构造读取数据的工具类 Dataset 与 DataLoader pytorch Data学习一 DataLoader的封装方法可以参考 Pytorch DataLoader一次性封装多种数据集
  • 在pycharm中升级pip失败和pip安装pytorch torchvision opencv

    pytorch官网 https pytorch org get started locally 查看版本 pip version pip 20 2 3 from c users 14172 pycharmprojects pythonpro
  • ping命令知识详解

    1 Ping的基础知识 Ping 是一个十分好用的TCP IP工具 功能 用来检测网络的连通情况和分析网络速度 2 Ping命令详解 参数意思和使用 t Ping指定的计算机直到中断 a 将地址解析为计算机名 n count 发送 coun
  • Spring--Bean相关

    你对Spring中的bean了解吗 都有哪些作用域 Scope Spring 官方文档对 bean 的解释是 In Spring the objects that form the backbone of your application
  • html2canvas生成图片底部出现白边儿的解决方法

    场景 使用html2canvas的时候 生成的图片底部出现了白边 产生白边原因 可能是由于像素渲染问题导致的 移动设备的屏幕像素密度 Pixel Density 较高 有时会导致在两个相邻元素之间出现细小的间隙或白线 解决方法 将canva
  • 解决 ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 问题

    解决 ERROR 1045 28000 Access denied for user root localhost using password YES 问题 最近新装好的mysql在进入mysql工具时 总是有错误提示 mysql u r
  • [leetcode 周赛 150] 1161 最大层内元素和

    目录 1161 Maximum Level Sum of a Binary Tree 最大层内元素和 描述 思路 代码实现 1161 Maximum Level Sum of a Binary Tree 最大层内元素和 描述 给你一个二叉树
  • 网络编程(详)

    一 概述 计算机网络 是指将地理位置不同的具有 独立功能的多台计算机及其外部设备 通过通信线路连接起来 在网络操作系统 网络管理软件及网络通信协议的管理和协调下 实现资源共享和信息传递的计算机系统 网络编程 在网络通信协议下 实现网络互连的
  • MATLAB—GUI新手入门教程

    GUI界面基本操作 1 GUI界面介绍 2 各个控件的使用方法 2 1 1 按钮 2 1 2 滑动条 2 1 3 文本框 2 1 4 单选框和复选框和切换按钮 2 1 5 弹出式菜单和列表框 2 1 6 按钮组 2 1 7 菜单编辑器 常见
  • 基于Xml方式Bean的配置-beanName个别名配置

    SpringBean配置详解 Bean的基础配置 例如前文涉及到的配置文件
  • 深入解读SpringBoot是什么?它到底有什么用?

    现在Spring Boot 非常火 各种技术文章 各种付费教程 多如牛毛 可能还有些不知道 Spring Boot 的 那它到底是什么呢 有什么用 今天给大家详细介绍一下 SpringBoot相关的教程 我是跟着动力节点王鹤老师讲的spri
  • Selenium Web自动化基础

    1 selenium环境配置 selenium是一个python的开源库 使用pip就可以安装 直接在cmd或者pycharm的终端执行pip install selenium 即可完成selenium库的安装 如果出现以下 Error c
  • 跟着angularjs2官方文档学习(四)