最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Loading External URL in Angular2 router-outlet - Stack Overflow

programmeradmin2浏览0评论

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

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

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

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

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

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

Share Improve this question asked Aug 9, 2016 at 23:29 UnderWoodUnderWood 8813 gold badges14 silver badges23 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Just create a ponent to render inside <ng-outlet> by using the routing config. Then you ponent 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.ponent.html',
    styleUrls: ['./external-page.ponent.css']
})

export class ExternalPageComponent implements OnInit {

    title = 'app works!';

    constructor(private _stellarService: StellarService) {
    }

    ngOnInit(): void {
    }

}

Then your ponent 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.

did you get answer for this ?

You can have a ponent as mentioned here . Import and add it to your NgModule; After that import it in the page you want and use the selector instead of <router-outlet>.

发布评论

评论列表(0)

  1. 暂无评论