ngRx 官方示例分析 - 5. components
组件通过标准的 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的更多相关文章
- ngRx 官方示例分析 - 3. reducers
上一篇:ngRx 官方示例分析 - 2. Action 管理 这里我们讨论 reducer. 如果你注意的话,会看到在不同的 Action 定义文件中,导出的 Action 类型名称都是 Action ...
- ngRx 官方示例分析 - 2. Action 管理
我们从 Action 名称开始. 解决 Action 名称冲突问题 在 ngRx 中,不同的 Action 需要一个 Action Type 进行区分,一般来说,这个 Action Type 是一个字 ...
- ngRx 官方示例分析 - 1. 介绍
ngRx 的官方示例演示了在具体的场景中,如何使用 ngRx 管理应用的状态. 示例介绍 示例允许用户通过查询 google 的 book API 来查询图书,并保存自己的精选书籍列表. 菜单有两 ...
- ngRx 官方示例分析 - 4.pages
Page 中通过构造函数注入 Store,基于 Store 进行数据操作. 注意 Component 使用了 changeDetection: ChangeDetectionStrategy.OnPu ...
- ngRx 官方示例分析 - 6 - Effect
@ngrx/effect 前面我们提到,在 Book 的 reducer 中,并没有 Search 这个 Action 的处理,由于它需要发出一个异步的请求,等到请求返回前端,我们需要根据返回的结果来 ...
- Halcon斑点分析官方示例讲解
官方示例中有许多很好的例子可以帮助大家理解和学习Halcon,下面举几个经典的斑点分析例子讲解一下 Crystals 图中显示了在高层大气中采集到的晶体样本的图像.任务是分析对象以确定特定形状的频率. ...
- RocketMQ源码分析之从官方示例窥探:RocketMQ事务消息实现基本思想
摘要: RocketMQ源码分析之从官方示例窥探RocketMQ事务消息实现基本思想. 在阅读本文前,若您对RocketMQ技术感兴趣,请加入RocketMQ技术交流群 RocketMQ4.3.0版本 ...
- DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版原创发布-带官方示例程序版
关于 DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版------------- ...
- DotNetBar for Windows Forms 12.5.0.2_冰河之刃重打包版原创发布-带官方示例程序版
关于 DotNetBar for Windows Forms 12.5.0.2_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版-------------- ...
随机推荐
- MySQL:表的操作 知识点难点总结:表完整性约束及其他常用知识点二次总结🙄
表操作 一 : 修改表表表表表表表表表: ALTER TABLE 语法 1. 改表名rename alter table 表名 rename 新表名 2. 增加字段add alter table 表名 ...
- leetcode — reorder-list
/** * Source : https://oj.leetcode.com/problems/reorder-list/ * * Given a singly linked list L: L0→L ...
- js介绍
---恢复内容开始--- js介绍 最近学习了js,那么我今天给大家介绍下js.希望对初学者有些帮助. js就是常说的JavaScript.JavaScript是目前世界上最流行的编程语言之一.这门语 ...
- 利用pip批量更新python库
如果python库比较旧,需要更新到最新版本,可以利用pip工具. DOS命令行下,输入pip -V查看pip版本,可以先把pip更新到新版本. 查看系统里过期的python库 pip list #列 ...
- 自学Aruba1.4-WLAN厂家魔力象限
点击返回:自学Aruba之路 1.4 自学Aruba1.4-WLAN厂家魔力象限 以下为2017<有线和无线局域网接入基础设施的魔力象限>报告: Aruba.cisco为无线领域 ...
- ztree使用font-awesome字体的问题,
ztree要使用自定义图标字体的时候 需要自己做皮肤cssstyle,官方有文档,但是有些时候我们值需要简单的设置图标字体class样式 是没办法使用的,我们需要对两个函数进行修改. 下面是两个函数请 ...
- Promise实现小球的运动
Promise简要说明 Promise可以处理一些异步操作:如像setTimeout.ajax处理异步操作是一函数回调的方式;当然ajax在jQuery版本升级过程中,编写方式也有所变动. P ...
- 使用Linq确定序列是否包含任何元素
假设我们有一个集合,想要判断这个集合中是否包含任何元素可以使用Linq中的Any() List<string> list = new List<string> { " ...
- ConstraintLayout知识记录
一.准备工作 1. 确保SDK Tools已经下载了ContraintLayout的支持库. 2. gradle中增加对ConstraintLayout的依赖. compile 'com.andr ...
- C#学习笔记-基础知识篇(不定期更新)
1.父类必须包含构造函数么? 父类必须要有一个构造函数,有参无参都可以. 构造函数是对象的基本,没有构造函数就没有对象,若父类中显示的有参数的构造函数,在子类继承就必须写一个构造函数来调用父类的构造函 ...