Angular TypeScript 框架学习笔记
2020-01-13 02:02
375 查看
Angular TypeScript 框架学习笔记
版本
8.0
TypeScript版本
3.4.5
接口对象
必须声明在组件配置声明至上,
import之下
声明
必须指定参数数据类型
// 定义接口数据类型 // 相当于定义了一个全局obj对象 // 并定义每个键值的数据类型 // 方便内部参数继承 interface WebData { StartTime: null | number; EndTime: null | number; Department: null | number; BusinessType: null | number; }
继承
在
class内声明变量继承接口
// class 内声明变量,数据类型为 webData 接口的数据格式 // 相当于在 class 内声明了一个全局 obj 对象 // 必须设定默认值 SearchData: WebData = { StartTime: null, EndTime: null, Department: null, BusinessType: null };
class
class内声明变量方法
不主动声明变量类型
// 数据类型默认为 any dateFormat = 'yyyy-MM-dd';
主动声明变量类型
SelectionDepartmentSelectionValue: string | number = 'any';
数组变量声明方式
SelectTimePeriodTypeDataList: Array<{ id: string, label: string }> = [ { id: 'any', label: '不限时间' }, { id: 'ToDay', label: '今天' }, { id: 'YesterDay', label: '昨天' }, { id: 'TheWeek', label: '本周' }, { id: 'LastWeek', label: '上周' }, { id: 'TheMonth', label: '本月度' }, { id: 'LastMonth', label: '上月度' }, { id: 'TheQuarter', label: '本季度' }, { id: 'LastQuarter', label: '上季度' }, { id: 'TheYear', label: '本年度' }, { id: 'LastYear', label: '上年度' } ];
修改 class 内变量值
this指向的是
class本身
export class SearchConditionComponent implements OnInit { // class 内声明变量,数据类型为 webData 接口的数据格式 // 相当于在 class 内声明了一个全局 obj 对象 // 设定默认值 SearchData: WebData = { StartTime: null, EndTime: null, Department: null, BusinessType: null }; // 开始时间 StartingTime: Date = new Date(); // 结束时间 EndTime: Date = new Date(); dateFormat = 'yyyy-MM-dd'; // 开始时间 StartingTime: Date = new Date(); // 结束时间 EndTime: Date = new Date(); constructor(private fb: FormBuilder) { } ngOnInit(): void { this.StartingTime = setHours(this.StartingTime, 0); this.StartingTime = setMinutes(this.StartingTime, 0); this.StartingTime = setSeconds(this.StartingTime, 0); this.EndTime = setHours(this.EndTime, 23); this.EndTime = setMinutes(this.EndTime, 59); this.EndTime = setSeconds(this.EndTime, 59); // this.SearchData.StartTime = getUnixTime(this.StartingTime); this.SearchData.EndTime = getUnixTime(this.EndTime); console.log(this.SearchData); } }
表单
input
双向绑定
<input nz-input placeholder="" autocomplete="off" nzSize="small" [(ngModel)]="SearchData.CustomerName" />
转载于:https://my.oschina.net/u/3756690/blog/3070819
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 《Angular(ng-book2)权威指南》学习笔记2——初步学习typescript
- angular2 学习笔记 (Typescript - Attribute & reflection)
- Angular学习笔记之集成第三方UI框架、组件
- Angular学习笔记之集成三方UI框架、控件的示例
- 前端框架angular学习笔记(一)
- 【深度学习笔记002 神经网络与主流框架】
- VS2010 C++ MFC框架学习笔记5 - C++面向对象编程基础1
- ASP.NET MVC2框架验证学习笔记
- jfinal框架教程-学习笔记(一)
- ASP.NET MVC2框架验证学习笔记
- 学习ASP.NET MVC5框架揭秘笔记-传统MVC模式
- Angular 学习笔记 ( 链接服务器 )
- hadoop 学习笔记:mapreduce框架详解
- Laravel框架学习笔记之批量更新数据功能
- 大数据技术学习笔记之Hadoop框架基础4-MapReduceshuffer过程详解及zookeeper框架学习
- 【学习笔记】Silverlight框架:Jounce(1)——概述
- MFC开发-学习笔记-象棋(中)-实现赢棋的判断及bug修复,单机象棋基本框架完成
- 阿里巴巴分布式服务框架dubbo学习笔记
- Python unittest 测试框架学习笔记
- hadoop 学习笔记:mapreduce框架详解