canvas(二) lineCap demo
Input与Output都是属性装饰器。
通常用于父子组件通信使用。
@Input
用来定义组件内的输入属性。
.d.ts 文件中定义如下:
export interface InputDecorator {
(bindingPropertyName?: string): any;
new (bindingPropertyName?: string): any;
}
由定义知道, 绑定的属性名是个可写参数。
因此,我们可以这定义 Input。
(1)不带参数名
@Input() count: number =0
在父组件使用时,传入的参数值如下:
<app-counter [count]="parentCount"></app-counter>
此时,在父组件传入的参数名,默认就是 count。
(2)带参数名
@Input('inputValue') count: number = 0
在父组件使用时,传入的参数值如下:
<app-counter [inputValue]="parentCount"></app-counter>
此时,在父组件传入的参数名,就是我们定义的属性名 inputValue。
(3) setter & getter
相比 @Output,@Input多了这两个属性,可以用来约束属性的设置和获取。
语法格式如下:
@Input()
set count() {
//逻辑值处理
} get count():T{
// 逻辑处理后返回值
return ...;
}
(4) ngOnchanges
当数据绑定输入值属性的值发生变化时,会触发 ngOnChanges()
语法如下:
ngOnChanges(changedEles : SimpleChange) {
// changedEles['属性名']
}
SimpleChange 会有三个值:
previousValue: any;
currentValue: any;
firstChange: boolean;
@Output
用来定义组件内的输出属性。
export interface OutputDecorator {
(bindingPropertyName?: string): any;
new (bindingPropertyName?: string): any;
}
当子组件的数据发生变化,需要通知父组件时,常常使用 EventEmitter。 使用方法:
1、子指令创建一个 EventEmitter 实例,作为输出属性导出。
@Output() changeCount : EventEmitter<any> = new EventEmitter<any>(); // 然后在某个时刻将信息发给父组件,一般在某个函数中
// 发送的信息可以是任何类型的
this.changeCount.emit(any)
2、父组件通过事件名称,获取子组件发过来的数据。
// 子组件事件名称 ="父组件函数名称($event)"
// 其中,$event 就是 子组件传送过来的数据
<app-counter [count]="initialCount" (changeCount)="parentChangeCount($event)"></app-counter>
@Input 与 @ Output综合代码如下:
子组件代码
使用 ng g c counter 命令生成组件代码。
counter.component.html
<p>当前值: {{ count }}</p>
<button (click)="increment()"> + </button>
<button (click)="decrement()"> - </button>
import { Component, OnInit , Input, OnChanges, SimpleChanges , Output , EventEmitter} from '@angular/core';
@Component({
selector: 'app-counter',
templateUrl: './counter.component.html',
styleUrls: ['./counter.component.scss']
})
export class CounterComponent implements OnInit, OnChanges {
@Output() changeCount: EventEmitter<any> = new EventEmitter<any>();
constructor() { }
ngOnInit() {
}
_count: number = 0;
@Input()
set count (num: number) {
this._count = num;
}
get count(): number {
return this._count;
}
increment() {
this.count++;
}
decrement() {
this.count--;
this.changeCount.emit({
count: this._count,
fromChildFun: 'decrement'
});
}
ngOnChanges(changedEles: SimpleChanges) {
console.dir(changedEles['count']);
}
}
父组件
<app-counter [count]="parentInitialCount" (changeCount)="parentChangeCount($event)"></app-counter>
parentInitialCount: number = 0;
parentChangeCount($event) {
console.dir($event);
}
canvas(二) lineCap demo的更多相关文章
- HTML5 之Canvas 绘制时钟 Demo
<!DOCTYPE html> <html> <head> <title>Canvas 之 时钟 Demo</title> <!--简 ...
- 分享一个非常屌的eazyui二开demo
eazyui二开Demo非常吊,里面各种非常吊的样例,最喜欢的是 多文件进度条上传,一次可多选,还有流程,还有文本编辑器 非常简洁的 不像一些官网各种复杂的东西.主要为自己保留一份, 在线demo在 ...
- 基于canvas二次贝塞尔曲线绘制鲜花
canvas中二次贝塞尔曲线参数说明: cp1x:控制点1横坐标 cp1y:控制点1纵坐标 x: 结束点1横坐标 y:结束点1纵坐标 cp2x:控制点2横坐标 cp2y:控制点2纵坐标 z:结束点2横 ...
- canvas画箭头demo
效果图: 代码: <!DOCTYPE html> <html> <title>canvas画箭头demo</title> <body> &l ...
- canvas二三事之签名板与视频绘制
今天,不知道怎么的就点开了语雀,然后就看到了<HTML5 Canvas 教程>,开始了canvas的研究(学习)之旅. 首先,想到的第一个东西就是签名板,上代码: <canvas i ...
- 第155天:canvas(二)
一.添加样式和颜色 在前面的绘制矩形章节中,只用到了默认的线条和颜色. 如果想要给图形上色,有两个重要的属性可以做到. fillStyle = color 设置图形的填充颜色 strokeSt ...
- canvas 画圈 demo
html代码: <canvas id="clickCanvas2" width="180" height="180" data-to ...
- RobotFrameWork接口报文测试-----(二)demo的升级版
在上一篇,简单的demo实现了讲xml的数据发送服务器端并取得recvi_buf,然后进行了简单的解析的操作.现在就要解决之前提过的2个问题: 1. 步骤这么多,难道每写一个脚本都要重复一次么? 2. ...
- html 5 canvas 绘制太极demo
一个练习canvas的小案例.其中若有小问题,欢迎大神拍砖……^_* 代码效果预览地址:http://code.w3ctech.com/detail/2500. <div class=" ...
随机推荐
- C# winform 打开主界面并关闭登录界面
在winform 界面编程中,我们有时候要在主界面打开之前先显示登录界面,当登录界面用户信息校验正确后才打开主界面,而这时登陆界面也完成使命该功成身退了. 目前有两种方法可实现: 方法1. 隐藏登录界 ...
- nginx里proxy_pass有无/的区别
nginx在反向代理的时候,proxy_pass需要指定路径,有无"/"的区别,如下: location /lile { 配置一: proxy_pass http://192. ...
- ueditor的简单用法
先粘贴未使用ueditor之前的代码: <body> <label for="input_content">作答区:</label> <t ...
- Maven+Spirng+Mybatis+CXF搭建WebService服务
https://jingyan.baidu.com/article/39810a23b1de2fb637fda66c.html
- Excel技巧--实现交叉查询
如上图,要实现某个地区和某个产品的销售额查询显示.可以使用Match和Index函数的使用来实现: 1.产品名称和城市栏,制作成列表可选:使用“数据”-->“数据验证”的方法. 2.先在旁边空位 ...
- Windows驱动开发
http://blog.csdn.net/sagittarius_warrior/article/details/51000241
- C#编程经验-VS Debug
F11 OneStepDebugF10 ProcessDebugbreakPointDebug(quick location,then use one step debug)
- Android批量验证渠道、版本号(Linux版)
功能:可校验单个或目录下所有apk文件的渠道号.版本号(Linux版本)使用说明:1.copy需要校验的apk文件到VerifyChannelVersion目录下2../VerifyChannelVe ...
- cookie and sesssion
会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...
- Tcp三次挥手和四次挥手
三次握手: (1) 第一次握手:建立连接时,客户端A发送SYN包(SYN=j)到服务器B,并进入SYN_SEND状态,等待服务器B确认 (2) 第二次握手:服务器B收到SYN包,必须确认客户A的S ...