且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Angular2路由器出口中加载外部URL

更新时间:2022-04-26 04:48:06

只需使用路由配置创建要在<ng-outlet>内部呈现的组件. 然后,您内部的组件模板应该有一个<iframe>指向您的外部站点.

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.