python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Angular 5 Constant

Angular 5 Constant and Global Variables

How to CREATE constant in your Angular 5 Apps? A constant is a value that can’t be changed by the program during normal execution.
Constants are of fixed values that do not change during the execution of a program. There are various types of constants. The Constant types are – Numeric, Character, Integer and many more.

And constant class looks like –
export class AppConstants {
    public static get baseURL(): string { return "http://localhost:4200/api"; }

And Use of constant in Services –
import { Injectable } from '@angular/core';
import {HttpClient, HttpParams, HttpHeaders} from "@angular/common/http";
import { Employee } from './employee';
import{ AppConstants} from '../app/constants'

export class EmployeeService {
  //variable initialization
  headers : any;
  _baseURL : string;

  //constructor initialization
  constructor(private _htc:HttpClient) {
      this.headers = new HttpHeaders().set('content-type', 'application/json');
      this._baseURL = AppConstants.baseURL;

  // POST employee - for creating a New employee.
  addEmployee(emp :any){
    var employee = {,
    return<Employee>(this._baseURL+'/Employees/Add', employee, (this.headers));

  //DELETE employee - for delete employee.
  deleteEmployee(id :string){    
    return this._htc.delete<Employee>(this._baseURL+'/Employees/Delete/'+id);


Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions