Multiple version JAVA in Ubuntu

Install JDK 8

sudo apt-get update ; sudo apt-get install openjdk-8-jre-headless
sudo  update-java-alternatives --list

to list off all the Java installations on a machine by name and directory, and then run

sudo  update-alternatives --config java

to choose which JRE/JDK to use.If you want to use different JDKs/JREs for each Java task, you can run can be configured (java, javac, javah, javaws, etc). And then

sudo  update-alternatives --config [javac|java|javadoc|etc.]

will associate that Java task/command to a particular JDK/JRE.

How to Upgrade MySQL from 5.6 to 5.7 on CentOS 7

Here is my worked commands:

mysql -V
yum repolist all | grep mysql
sudo yum-config-manager --enable mysql57-community-dmr
sudo yum-config-manager --enable mysql57-community
sudo yum-config-manager --disable mysql56-community
yum repolist all | grep mysql
sudo yum install mysql-community-server
sudo service mysqld status
sudo service mysqld stop
sudo service mysqld start
mysql -V
sudo mysql_upgrade -u root -p --force
sudo service mysqld stop
sudo service mysqld start

 

This command is used for make your old user account can be upgraded to new version to be used.

sudo mysql_upgrade -u root -p –force

How to use css class in the innerHtml binding in angular

Credit goes to this link:

http://stackoverflow.com/questions/36265026/angular-2-innerhtml-styling

“Angular adds all kinds of CSS classes to the HTML it adds to the DOM to emulate shadow DOM CSS encapsulation to prevent styles of bleeding in and out of components. Angular also rewrites the CSS you add to match these added classes. For HTML added using [innerHTML] these classes are not added and the rewritten CSS doesn’t match.”

As a workaround try

  • for CSS added to the component
:host /deep/ mySelector {
  background-color: blue;
}
  • for CSS added to index.html
body /deep/ mySelector {
  background-color: green;
}

How to use jQuery in Angular 2

First install jQuery with NPM: npm install --save jquery

Update scripts key in your angular-cli.json to include jQuery

"scripts": [
  "../node_modules/jquery/dist/jquery.js"
]

You should stop angular-cli and rerun it using ng serve.

Now jQuery is available globally in the application. Whenever you need to use just declare $ or jQuery at the top like so:

import { Component, OnInit } from '@angular/core';  
// import line is this one
declare var $:any;
//declare var jQuery: any;

export default class Random implements OnInit {  
  ngOnInit() {
    // $ will be availble
    console.log($);
  }
}

 

jQuery THIS trap in Angular 2

Because of the access scope for jQuery, you must be careful when you use the jQuery in the  Angular. such as for this code  :

resultList  :string[] = [];
       myarray  :string[] = ['s1','s2','s3'];

       ............
                this.resultList.push('testS1');
                jQuery.each( this.myarray, function( index, v ) {
                        this.resultList.push(  v );
                });
       ...............

The error you will get will be :
Cannot read property ‘push’ of undefined

Correct way is:

       resultList  :string[] = [];
       myarray  :string[] = ['s1','s2','s3'];

       ............
                this.resultList.push('testS1');
                let __mythis = this;
                jQuery.each( this.myarray, function( index, v ) {
                        __mythis.resultList.push(  v );
                });
       ...............

How to pass data via event from child to parent component in Angular 2

At the child, I have a boolean data want to send to parent if a function method is clicked. What should I do?

Parent code is here. (onChangeDone) to receive an output from the child component and it can trigger a method to receive the event from the child too:

HTML Tag:
...

<childcomp (onChangeDone)="onChangeD($event)"> </childcomp>

....

TS code part:

export class ParentComp {

 onChangeD( result: boolean ) {
        if ( result ) // data changed
          { }
        else { }
    }


...

At the child component, answer is @Output() and together with the EventEmitter:

export class ChildComp implements OnInit {

    @Output() onChangeDone = new EventEmitter<boolean>();
    .....

    clickButton(): void {
     .....
     this.onChangeDone.emit(true);
     ....
    }

How to input a data from parent to child component in Angular 2

At the parent  I have a flag is createOrUpdate want to be sent to child component, parent code is here :

HTML Tag:
...

<childcomp [createOrUpdate]="createOrUpdate" > </childcomp >

....

TS code part:

export class ParentComp {
    createOrUpdate: boolean = true; // true for create, false for update
...

At the child component, answer is @Input  and same named variable to catch the input:

export class ChildComp implements OnInit {

    @Input() createOrUpdate: boolean;
    buttonText: string = 'Create New Car';
...
    ngOnInit() {
        if (this.createOrUpdate)
            this.buttonText = 'Create New Car';
        else this.buttonText = 'Update Car';
    }
....