ionic UI(3)TypeScript - handbook
1 Basic Types
boolean - var isDone :boolean = false;
number - var height: number = 6;
string - var name:string = ‘carl’;
name = “sillycat”;
Array - var list:number[] = [1,2,3];
var list:Array<number> = [1,2,3];
Enum - enum Color { Red, Green, Blue };
var c: Color = Color.Green;
usually, enum begin from 0, we can set the number as well.
enum Color {Red = 1, Green = 2, Blue = 4};
var colorName: string = Color[2];
alert(colorName);
The alert message is ‘Green'
Any - var notSure: any = 4;
notSure = “may be a string instead”;
notSure = false;
Void - function warnUser(): void {
alert(“warning message.");
}
2 Interfaces
interface LabelledValue {
label: string;
}
This interface requires there is a property label in the parameter object.
Optional Properties in Interface
interface SquareConfig {
color?: string;
width?: number;
}
Class Types
interface ClockInterface {
currentTime:Date;
setTime(d:Date);
}
class Clock implements ClockInterface {
currentTime: Date;
setTime(d:Date) {
this.currentTime = d;
}
constructor(h:number, m: number) { }
}
Extending Interfaces
interface Shape {
color: string;
}
interface Square extends Shape {
sideLength: number;
}
var square = <Square>{};
square.color = “blue”;
square.sideLength = 10;
3 Classes
Inheritance of Class
class Animal {
name: string;
contractor(theName:string) { this.name = theName; }
move(meters: number = 0) {
alert(this.name + “ can move “ + meters + “m.")
}
}
class Snake extends Animal {
constructor(name:string) { super(name); }
move(meters = 5) {
alert(“slithering….");
super.move(meters);
}
}
Private/Public modifiers - public is always the default
Getter / Setter
var passcode = “secret passcode”;
class Employee {
private _fullName: string;
get fullName(): string {
return this._fullName;
}
set fullName(newName: string) {
if(passcode && passcode == “secret passcode”){
this._fullName = newName;
}else{
alert(“Unauthorized update of employee!");
}
}
}
var employee = new Employee();
employee.fullName = “Carl Luo”;
if(employee.fullName) {
alert(employee.fullName);
}
4 Modules
>tsc —out sample.js Validation.ts LettersOnlyValidator.ts ZipCodeValidator.ts Test.ts
5 Functions
default and optional parameters
function buildName(firstName:string, lastName?:string){
}
function buildName(firstName:string, lastName = “Smith”) {
}
6 Generics
More documents in the handbook, but I think I am ok that I only read the first few chapters.
http://www.typescriptlang.org/Handbook
References:
http://www.typescriptlang.org/Handbook
分享到:
相关推荐
导航到IONIC-Angular-Typescript-Sample目录: cd IONIC-Angular-Typescript-Sample 安装依赖项 npm install 在浏览器中运行应用 ionic serve 使用REST服务 请按照以下说明使用REST数据服务运行它: 将R
Angular-ionic-native-http-connection-backend.zip,离子型和iosionic本机http连接后端cors问题的解决方案,Angularjs于2016年发布,是Angularjs的重写版。它专注于良好的移动开发、模块化和改进的依赖注入。angular...
Angular-ionic3-start-theme.zip,Ionic3的开始主题有10个页面、模拟数据、提供者示例、存储、HTTP等…Ionic3的开始主题,Angularjs于2016年发布,是Angularjs的重写版。它专注于良好的移动开发、模块化和改进的依赖...
$ ionic start YOUR_APP_NAME blank$ cd YOUR_APP_NAME$ curl -o- https://raw.githubusercontent.com/kinumi/ionic-typescript-bootstrap/master/bootstrap.sh | bash在ionic.project添加以下内容非常方便。...
这是一个生动的回购,来自“ Ionic and Typescript”截屏的示例。 在这里,我们将遍历所有部分以使用Ionic V1和Typescript进行设置。 第1部分:建立构建步骤。 连结至YouTube 首先让我们创建一个项目 $ ionic ...
这是一个封装好的ionic日期选择器,下载解压,点击date.html即可查看效果。
ionic-字母索引-城市选择
ionic_project3-master.rar
ionic 3 for develop mobile apps native in mobile phone user
ionic-app-base-master.zip
Ionic4星级您可以提供自定义图标,... 对于ionic-3项目,请检查以下软件包: : 如何使用步骤1安装它npm i ionic4-star-rating 如下所示将ionic4-star-rating组件添加到您的page.html(父组件)中 <ionic4-star-rati
ionic 借助插件 cordova-plugin-wechat cordova-plugin-qqsdk 实现微信分享 QQ分享 微博分享
Angular-ionic4-starter-app.zip,Ionic 4待办事项列表应用程序。免费离子4示例应用程序。了解如何开始使用Ionic 4创建一个包含列表、表单和导航的简单应用程序。Ionic 4 Starter应用程序,Angularjs于2016年发布,是...
ionic-sublime-plugin 支持sublime2、3版本
离子vue分屏-vuex分支查看更新的代码-https: Ionic Vue Web组件-分屏又称SideMenu 5月20日更新-ionic...vue-router而不是router-vue 使用添加简单的身份验证示例进行状态管理修改以使用ionic / cli命令跑步ionic serve
例如,要使用默认选项卡界面启动一个新的 Ionic 项目,请确保已安装ionic实用程序: $ npm install -g ionic 然后运行: $ ionic serve使用打字稿和 sass 安装打字稿工具: npm install -g typescript 为了编译 ...
由于国内下载ionic3资源有时候会有错误产生,所以准备一份已经下载好的demo提供给大家下载!
由于国内下载ionic3资源有时候会有错误产生,所以准备一份已经下载好的demo提供给大家下载!
由于国内下载ionic3资源有时候会有错误产生,所以准备一份已经下载好的demo提供给大家下载!
ionic 2