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_冰河之刃重打包版-------------- ...
随机推荐
- 这些年常用的WEB开发工具和技术, 学会一半你找工作没问题
前言: 技术选型并不是一成不变的,需要根据技术的发展.项目实际情况和人员技能构成实际考虑,在此列出的只是这些年常用的. 开发环境 1. 主要开发语言:Java7, HTML, Javascript等 ...
- 深入浅出Android之学习笔记
1.查看启动log [2011-01-11 14:44:21 - BMI] Android Launch! [2011-01-11 14:44:21 - BMI] adb is running nor ...
- scrapy使用PhantomJS爬取数据
环境:python2.7+scrapy+selenium+PhantomJS 内容:测试scrapy+PhantomJS 爬去内容:涉及到js加载更多的页面 原理:配置文件打开中间件+修改proces ...
- jQuery DOM 元素方法 (十)
函数 描述 .get() 获得由选择器指定的 DOM 元素. .index() 返回指定元素相对于其他指定元素的 index 位置. .size() 返回被 jQuery 选择器匹配的元素的数量. . ...
- Jenkins:基于linux构建ivy项目
Jenkins:基于linux构建ivy项目 (二) 基于以上<Jenkins:VMware虚拟机Linux系统的详细安装和使用教程(一)>的配置再进行对ivy项目构建: 启动tomcat ...
- mysql自连接求累计金额
- Java学习笔记6(循环和数组练习题)
1.输出100到1000的水仙花数: public class LoopTest{ public static void main(String[] args){ int bai = 0; int s ...
- 机器学习 | 从加法模型讲到GBDT算法
作者:JSong, 日期:2017.10.10 集成学习(ensemble learning)通过构建并结合多个学习器来完成学习任务,常可获得比单一学习器显著优越的泛化性能,这对"弱学习器& ...
- C语言范例学习06-上
第六章 文件操作 前言:第五章是C语言在数学上的一些应用,我觉得没有必要,便跳过了.这章正如我标题所写的,是C语言在文件上的操作.学习了这个后,你们可以自行编辑一些所需的快捷程序,来实现一些既定的目的 ...
- 85、flask之wtforms
本篇导航: wtforms组件的使用 自定义From组件 一.wtforms组件的使用 1.flask中的wtforms WTForms是一个支持多个web框架的form组件,主要用于对用户请求数据进 ...