Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading External URL in Angular2 router-outlet

I am developing an application using Angular2. I have a component with the following template:

<div>
  <router-outlet></router-outlet>
</div>

Can someone please help me how to load an external URL 'www.example.com' in this div?

like image 912
UnderWood Avatar asked Aug 24 '26 21:08

UnderWood


1 Answers

Just create a component to render inside <ng-outlet> by using the routing config. Then you component template inside should have an <iframe> pointing to your external site.

import {Component, OnInit} from '@angular/core';

@Component({
    selector: 'app-external-page',
    templateUrl: './external-page.component.html',
    styleUrls: ['./external-page.component.css']
})

export class ExternalPageComponent implements OnInit {

    title = 'app works!';

    constructor(private _stellarService: StellarService) {
    }

    ngOnInit(): void {
    }

}

Then your component template should look like

<div>
    <iframe src="yourexternalpage url"></iframe>
</div>

Having a code like the one above, only remaining step if to configure a route in your routing.

like image 51
mspasiuk Avatar answered Aug 26 '26 10:08

mspasiuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!