0

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?

Sa E Chowdary
  • 2,075
  • 15
  • 31
AFwcxx
  • 467
  • 1
  • 4
  • 15
  • 6
    could this be typescript? – JanR Dec 06 '16 at 04:59
  • Possible duplicate of [What does this symbol mean in JavaScript?](http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript) which has a link to a question reguarding the specific symbol: http://stackoverflow.com/questions/39655737/javascript-strange-syntax-that-works-but-how – Tot Zam Dec 06 '16 at 05:00
  • 1
    possible duplicate of http://stackoverflow.com/questions/418799/what-does-colon-do-in-javascript – Jayanti Lal Dec 06 '16 at 05:02
  • 1
    The code you posted is not JS, possibly be TypeScript – DMaster Dec 06 '16 at 05:04
  • 1
    It's a TypeScript type annotation. –  Dec 06 '16 at 05:04

2 Answers2

3

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.

eko
  • 39,722
  • 10
  • 72
  • 98
coderdark
  • 1,481
  • 14
  • 30
0

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; }
Shai
  • 3,659
  • 2
  • 13
  • 26