在使用外部URL NG-包括AngularJS [英] Using external url in ng-include in AngularJS

查看:973
本文介绍了在使用外部URL NG-包括AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AngularJS在手的问题,需要一些三分球。

I have a problem in hand in AngularJS and need some pointers.

我有一个观点,我希望嵌入外部URL(例如: http://www.w3schools.com )。该嵌入式的HTML页面应该像点击和触摸像一个正常的HTML页面的事件。

I have a view where I want to embed an external url (e.g. http://www.w3schools.com). The embeded html page should respond to events like click and touch like a normal html page.

我用NG-include指令来获取工作。

I have used ng-include directive to get that working.

下面是一个code片断:

Here is a code snippet:

    <ion-content>
       <div ng-include src="'http://www.w3schools.com'"</div>
    </ion-content>

如果我加载外部HTML,我收到外部网页加载,但在页面内的所有链接都断了。如果我的任何点击加载的页面中,所有的链接都指向现在反而为localhost外部URL的。

If I load the external html, I am getting the external webpage loaded, but all the links inside the page are broken. If I click on any link inside the loaded page, all links point to localhost now instead of the external url.

我怎样才能解决这个问题呢?

How can I fix this problem?

感谢提前!

推荐答案

这听起来像你真的只是想主办的外部站点视图里面,然后你应该只在一个iframe链接。

It sounds like you really just want to host the external site inside your view, and then you should just link it in an iframe.

<iframe src="http://www.w3schools.com"></iframe>

如果你想要的东西的魔法/动态的东西的事情发生,你需要解析的内容并重写的URL,附加处理程序等原因,您的NG-包括并不像预期的工作是因为它只能读取其内容网址并将其嵌入到您的视图作为假设这只是你做(包括角标记),并希望外部托管出于某种原因的模板。

If you want something magic/dynamic stuff to happen, you will need to parse the content and rewrite the urls, attach handlers etc. The reason your ng-include does not work like expected is because it only reads the content of that url and embeds it into your view "as-if" it was just a template you made (including angular markup) and wanted to host externally for some reason.

这篇关于在使用外部URL NG-包括AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆