Typescript Class Creation


Hello everybody,

today I want to document some demos for class declaration in Angular 2. 

So, let's say you have following class declared:


import { Component, Injectable } from '@angular/core'
import { Http, Response } from '@angular/http'
export class Config {
    public apiKey: string = 'xxxxxyy117c24d8b9085187163f5d241';
    public url: string = 'https://public-api.blablacar.com/api/v2/trips?key=';
    constructor(private http: Http) {
    getReqUrl(): string{
        return this.url + this.apiKey;

Then the way to create it is the following:


    let conf = new Config();
    let url: string = conf.getReqUrl();

Take note, tht for conf we didn't put type clarification, but for url we clarified the type of variable.

No Comments

Add a Comment


Comments are closed