Thursday 29 November 2018

How to set environment variables in angular 6?



All variables which vary based on the environment, should be placed inside these two files appropriately. Check the examples given below for the API Endpoint.

// environment.ts environment variables
export const environment = {
  production: false,
  BackendAPIEndpoint: "https://dev.endpoint.com"
};

// environment.prod.ts environment variables
export const environment = {
  production: true,
  BackendAPIEndpoint: "https://prod.endpoint.com"
};

To access the variables, import the environment constant, and then use it as follows:

import { environment } from '../environments/environment'; //change path accordingly

Usage:
const BackendAPIEndpoint = environment.BackendAPIEndpoint;

Dealing with 1 or More Environment:

// environment.staging.ts environment variables
export const environment = {
  production: true
  BackendAPIEndpoint: "https://staging.endpoint.com"
};


Next, we need to make configuration changes to our angular.json – at the root of our workspace. This will enable Angular CLI to recognize our two new environments and use the new environment files we created in the previous step.

"configurations": {
   "production": {
       "fileReplacements": [
           {
              "replace": "src/environments/environment.ts",
               "with": "src/environments/environment.prod.ts"
           }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": false,
        "extractCss": true,
        "namedChunks": false,
        "aot": true,
        "extractLicenses": true,
        "vendorChunk": false,
        "buildOptimizer": true,
        "serviceWorker": true
   }
}

Your new configuration for staging environment should look like this:

"configurations": {
   "production": {
        ...
    },
    "staging": {
    "fileReplacements": [
     {
         "replace": "src/environments/environment.ts",
         "with": "src/environments/environment.staging.ts"
     }],
     "optimization": true,
     "outputHashing": "all",
     "sourceMap": true,
     "extractCss": false,
     "namedChunks": false,
     "aot": false,
     "extractLicenses": true,
     "vendorChunk": false,
     "buildOptimizer": true,
     "serviceWorker": true
   }
}

Building your App
Finally, to build your application with the new custom environment, use the –configurations=environment-name flag, as show below:

//for development environment
ng build

//for staging environment
ng build --prod

//for staging environment
ng build --configuration=staging

And that’s it, you can now configure your Angular Application.

Thanks

Saturday 3 November 2018

Wifi (internet) not working after upgrade from ubuntu 16.04 to ubuntu 18.04?

Hello All,

Do the following on terminal to overcome this issue:

#sudo /etc/resolv.conf

Added nameserver 8.8.8.8

and then

#sudo /etc/init.d/networking restart


Done!!!


How to upgrade ubuntu 14.04 to 18.04

Follow the following steps:

#do-release-upgrade
#lsb_release -a
#apt update
#apt upgrade
#apt dist-upgrade
#apt install update-manager-core
#do-release-upgrade


Thanks

Friday 24 August 2018

How to Create Dynamic associative array in typescript?

Hello



public data:Array<any> = [
{"id":10, "text": "First"},
{"id":11, "text": "Second"},
{"id":12, "text": "Third"},
{"id":10, "text": "Fourth"},
{"id":11, "text": "Fifth"},
{"id":13, "text": "Sixth"}
];
public array: any[][] = [];

for(let i: number=0;i<this.data.length;i++){
this.array[this.data[i].id] = this.array[this.data[i].id] || [];
this.array[this.data[i].id].push(this.data[i].text);
}

this.array.forEach(element => {
console.log(element);
});

Thursday 14 June 2018

How to install angular js in ubuntu 14.04

Hello,

Verify that you are running at least Node.js version 8.x or greater and npm version 5.x or greater by running node -v and npm -v in a terminal/console window. 


Then,

npm install -g @angular/cli

Thanks

How to upgrade nodejs and npm version in ubuntu 14.04

Hello,

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

Friday 14 October 2016

Remove new line or space between tags in xml

<?php
$xml = '<Pages>
<Page Name="test">
<controls><test>this is a test.</test></controls>
</Page>
<page Name="User">
<controls><name>Sunil</name></controls>
</page>
</Pages>';
echo $xml;


$re = '/(?<=\>)(\r?\n)|(\r?\n)(?=\<\/)/';
$substring = '';

$xml = preg_replace($re, $substring, $xml);

echo "The result of the substitution is ".$xml;
?>