I found this code in Ionic framework:
import { AlertController } from 'ionic-angular';
export class MyPage {
constructor(public alertCtrl: AlertController) {
}
what does that :
in alertCtrl: AlertController
means?
I found this code in Ionic framework:
import { AlertController } from 'ionic-angular';
export class MyPage {
constructor(public alertCtrl: AlertController) {
}
what does that :
in alertCtrl: AlertController
means?
The : in typescript means type assignment/annotation...
alertCtrl: AlertController
means declare alertCtrl
as AlertController
, which will only accept Objects
of AlertController
type.
count:number
means declare count as number, which will only accept number
.
name:string
means declare name as string, which will only accept a string
.
The code is written in TypeScript, which is a language that is compiled to JavaScript.
The :
symbol is used to specify typing. It can come after a variable declaration to specify its type, after a function's parameter or after the function's heading to specify it's return type (which can be void).
Examples:
let a: number = 8;
function (b: number): number { return b; }