'New url is getting appended with localhost url

Url what i am getting from dynamically from user that i am trying to open in a new tab, its getting open in new tab but the localhost url is getting appended along with the dynamic url.

      @Injectable()
    export class WindowRef {
        constructor() {}
        getNativeWindow() {
            return window;
         }
    }

export class UrlTab implements OnInit{

          constructor(private winRef: WindowRef) {
           this.nativeWindow = winRef.getNativeWindow();
       }

    //method getting called on click of <a></a> from html
          assignActity(type: string): void {
           var newWindow = this.nativeWindow.open("www.gmail.com");
    }
}


Solution 1:[1]

You either need to include the protocol ("http://", "https://", etc.) when you call the .open() method call.

Example:

var newWindow = this.nativeWindow.open("http://www.gmail.com");

Or, better still, you can make it "protocol-less" by prepending just the "//" to the URL.

Example:

var newWindow = this.nativeWindow.open("//www.gmail.com");

When omitting the protocol, the browser assumes that you're referring to a relative URL.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1