从内angularJS部分链接到不同的域的外部URL不同、部分、链接、angularJS

由网友(情域)分享简介:所有我想要做的是包括部分的HTML中的锚标记,链接到外部网站。是这一标准的HTML中,code,简直是:All I am trying to do is include an anchor tag inside the html of a partial that links to an external site....

所有我想要做的是包括部分的HTML中的锚标记,链接到外部网站。是这一标准的HTML中,code,简直是:

All I am trying to do is include an anchor tag inside the html of a partial that links to an external site. Were this standard html, the code would simply be:

<a href="http://www.google.com" target="_blank">google</a>

这么简单,因为这是,我似乎无法找到让过去的角度截取的路线(或者替换我的锚用的 https://docs.angularjs.org/api/ng/directive/a 指令无意?)。

我有这么冲刷和网络的其余部分,看到解决方案的大量处理:一个页面内的SPA在同一个域中内的链接,路由,路由(ALA $ anchorScroll),但这些都不是我的问题没错。

I have scoured SO and the rest of the web and seen a myriad of solutions for dealing with: links within the same domain, routing within the SPA, routing within a page (ala $anchorScroll) but none of these are my issue exactly.

我怀疑它可能有事可做使用$ SCE但我是一个角度的n00b并没有真正知道如何正确地使用该服务。我试着在我的视图控制器以下内容:

I suspect it may having something to do with using $sce but I am an Angular n00b and not really sure how to properly use that service. I tried the following in my view controller:

$scope.trustUrl = function(url) {
    return $sce.trustAsResourceUrl(url);
}

与相应的

<a ng-href="{{ trustUrl(item) }}">Click me!</a>

(如下所述:Binding在angularjs模板外部URL)

但似乎并没有这样的伎俩(我结束了刚刚HREF ={{,在呈现的页面)。

but that did not seem to do the trick (I ended up with just href="{{" in the rendered page).

使用这样一个普通的锚链接:

Using a plain vanilla anchor link like this:

<a href="http://www.google.com">google</a>

也没有这样的伎俩(即使一些网上告知,标准HREF会引起角一个完整的页面重载:AngularJS - 我该怎么做重定向一个完整的页面加载)

我也试过将目标= _self属性,但似乎没有任何效果无论是。

I also tried adding the target=_self" attribute but that seemed to have no effect either.

我是否需要写一个自定义的指令,因为这里所描述?

Do I need to write a custom directive as described here?

Conditionally添加目标=&QUOT; _blank&QUOT;与角JS 链接

这一切似乎对于这样一个简单的动作太复杂,我觉得我很想念我的n00bishness东西很明显,至少我希望如此,因为这个过程是感觉很繁重的只是链接到另一个网址。

This all seems way too complicated for such a simple action and I feel like I am missing something obvious in my n00bishness, at least I hope so because this process is feeling very onerous just to link to another url.

在此先感谢任何解决方案,咨询,裁判和方向。

Thanks in advance for any solutions, advice, refs or direction.

推荐答案

事实证明,我确实在事实上已经在页面中的所有锚链接绑定到一个事件侦听器和被覆盖。由于该code是根本的方式在页面工作,我不想惹它。相反,我用它绕过NG-点击调用新的URL,如下所示:

It turns out that I did in fact have all anchor links in the page bound to an event listener and being overridden. Since that code was fundamental to the way the page worked I did not want to mess with it. Instead I bypassed it by using ng-click to call the new url as follows:

HTML

<a class="navLinkHcp" href="{{hcpurl}}" title="Habitat Conservation Plan" target="_blank" ng-click="linkModelFunc(hcpurl)">Habitat Conservation Plan</a>

控制器:

$scope.hcpurl = 'http://eahcp.org/index.php/about_eahcp/covered_species';

$scope.linkModelFunc = function (url){
  console.log('link model function');
  $window.open(url);
}

和瞧!好去。再次感谢KevinB在对着我诉说什么,这可能是问题。

And voila! Good to go. Thanks again to KevinB for cluing me in that this was probably the issue.

阅读全文

相关推荐

最新文章