组件通过标准的 Input 和 Output 进行操作,并不直接访问 store.

/app/components/book-authors.ts

import { Component, Input } from '@angular/core';

import { Book } from '../models/book';

@Component({
selector: 'bc-book-authors',
template: `
<h5 md-subheader>Written By:</h5>
<span>
{{ authors | bcAddCommas }}
</span>
`,
styles: [`
h5 {
margin-bottom: 5px;
}
`]
})
export class BookAuthorsComponent {
@Input() book: Book; get authors() {
return this.book.volumeInfo.authors;
}
}

/app/components/book-detail.ts

import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Book } from '../models/book'; @Component({
selector: 'bc-book-detail',
template: `
<md-card *ngIf="book">
<md-card-title-group>
<md-card-title>{{ title }}</md-card-title>
<md-card-subtitle *ngIf="subtitle">{{ subtitle }}</md-card-subtitle>
<img md-card-sm-image *ngIf="thumbnail" [src]="thumbnail"/>
</md-card-title-group>
<md-card-content>
<p [innerHtml]="description"></p>
</md-card-content>
<md-card-footer class="footer">
<bc-book-authors [book]="book"></bc-book-authors>
</md-card-footer>
<md-card-actions align="start">
<button md-raised-button color="warn" *ngIf="inCollection" (click)="remove.emit(book)">
Remove Book from Collection
</button> <button md-raised-button color="primary" *ngIf="!inCollection" (click)="add.emit(book)">
Add Book to Collection
</button>
</md-card-actions>
</md-card> `,
styles: [`
:host {
display: flex;
justify-content: center;
margin: 75px 0;
}
md-card {
max-width: 600px;
}
md-card-title-group {
margin-left: 0;
}
img {
width: 60px;
min-width: 60px;
margin-left: 5px;
}
md-card-content {
margin: 15px 0 50px;
}
md-card-actions {
margin: 25px 0 0 !important;
}
md-card-footer {
padding: 0 25px 25px;
position: relative;
}
`]
})
export class BookDetailComponent {
/**
* Presentational components receieve data through @Input() and communicate events
* through @Output() but generally maintain no internal state of their
* own. All decisions are delegated to 'container', or 'smart'
* components before data updates flow back down.
*
* More on 'smart' and 'presentational' components: https://gist.github.com/btroncone/a6e4347326749f938510#utilizing-container-components
*/
@Input() book: Book;
@Input() inCollection: boolean;
@Output() add = new EventEmitter<Book>();
@Output() remove = new EventEmitter<Book>(); /**
* Tip: Utilize getters to keep templates clean
*/
get id() {
return this.book.id;
} get title() {
return this.book.volumeInfo.title;
} get subtitle() {
return this.book.volumeInfo.subtitle;
} get description() {
return this.book.volumeInfo.description;
} get thumbnail() {
return this.book.volumeInfo.imageLinks.smallThumbnail;
}
}

ngRx 官方示例分析 - 5. components的更多相关文章

  1. ngRx 官方示例分析 - 3. reducers

    上一篇:ngRx 官方示例分析 - 2. Action 管理 这里我们讨论 reducer. 如果你注意的话,会看到在不同的 Action 定义文件中,导出的 Action 类型名称都是 Action ...

  2. ngRx 官方示例分析 - 2. Action 管理

    我们从 Action 名称开始. 解决 Action 名称冲突问题 在 ngRx 中,不同的 Action 需要一个 Action Type 进行区分,一般来说,这个 Action Type 是一个字 ...

  3. ngRx 官方示例分析 - 1. 介绍

    ngRx 的官方示例演示了在具体的场景中,如何使用 ngRx 管理应用的状态. 示例介绍 示例允许用户通过查询 google 的 book  API  来查询图书,并保存自己的精选书籍列表. 菜单有两 ...

  4. ngRx 官方示例分析 - 4.pages

    Page 中通过构造函数注入 Store,基于 Store 进行数据操作. 注意 Component 使用了 changeDetection: ChangeDetectionStrategy.OnPu ...

  5. ngRx 官方示例分析 - 6 - Effect

    @ngrx/effect 前面我们提到,在 Book 的 reducer 中,并没有 Search 这个 Action 的处理,由于它需要发出一个异步的请求,等到请求返回前端,我们需要根据返回的结果来 ...

  6. Halcon斑点分析官方示例讲解

    官方示例中有许多很好的例子可以帮助大家理解和学习Halcon,下面举几个经典的斑点分析例子讲解一下 Crystals 图中显示了在高层大气中采集到的晶体样本的图像.任务是分析对象以确定特定形状的频率. ...

  7. RocketMQ源码分析之从官方示例窥探:RocketMQ事务消息实现基本思想

    摘要: RocketMQ源码分析之从官方示例窥探RocketMQ事务消息实现基本思想. 在阅读本文前,若您对RocketMQ技术感兴趣,请加入RocketMQ技术交流群 RocketMQ4.3.0版本 ...

  8. DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版原创发布-带官方示例程序版

    关于 DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版------------- ...

  9. DotNetBar for Windows Forms 12.5.0.2_冰河之刃重打包版原创发布-带官方示例程序版

    关于 DotNetBar for Windows Forms 12.5.0.2_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...

随机推荐

  1. JavaScript实现ZLOGO: 用语法树实现多层循环

    原址: https://zhuanlan.zhihu.com/p/32571516 照例先上演示弱效果图. 演示地址照旧: 代码如下: 开始 循环4次 循环4次 前进50 左转90度 到此为止 右转9 ...

  2. volatile关键字的特性总结

    当一个变量定义为volatile后,它将具备两个特性: 1.保证此变量对所有线程的可见性,所谓"可见性",,是指当一个线程修改了这个变量的值,新值对于其他线程来说是可以立即得知的. ...

  3. 高效的CSS代码(2)

    ——阅读笔记,欢迎纠错^_^ 内容比较零散..... 1.让浮动元素的父容器根据元素的高度而自适应高度的方法: <div class="clearfix"><di ...

  4. 学习整理与细化(2)——HTML VS XHTML

    <html> <head>//文档头 <title>webpage title</title> </head> <body>// ...

  5. APP网络测试要点和弱网模拟

    当前APP网络环境比较复杂,网络制式有2G.3G.4G网络,还有越来越多的公共Wi-Fi.不同的网络环境和网络制式的差异,都会对用户使用app造成一定影响.另外,当前app使用场景多变,如进地铁.上公 ...

  6. python_第2课

    前言 回顾一下python+selenium基础,并整理相关知识点,分享给有需要,在前进道路上的朋友. 由于不是在python中敲的代码,有可能有缩进等相关错误,请自行检查 数据类型 #python中 ...

  7. VMware虚拟机下为Ubuntu添加磁盘

    20G的磁盘还是不够用啊,正好复习下磁盘分区和逻辑卷. 关闭虚拟机,打开VMware,右键虚拟机点击设置,点下下方的添加,就可以添加磁盘了. 进入虚拟机,查看: root@ubuntu:/# fdis ...

  8. 终端登入mysql

    mysql -u 用户名 -p 输入密码     1. 给root用户添加密码,密码为root     mysqladmin -u root -p password root 2. 通过终端连接ser ...

  9. findhex

    FindPattern(hD3D, 0x128000, (PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86&qu ...

  10. MySQL innodb_flush_method

    innodb_flush_method这个参数控制着innodb数据文件及redo log的打开.刷写模式,对于这个参数,文档上是这样描述的: 有三个值:fdatasync(默认),O_DSYNC,O ...