AngularJS< A>不工作的标签链接 [英] AngularJS <a> tag links not working

查看:205
本文介绍了AngularJS< A>不工作的标签链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对象的指数从搜索返回。该模板有所在项目的网址是从模型中的数据构建但在最后标记的A标签不工作的NG-重复。在NG-href和HREF是正确的,点击这个链接,但无法载入网页时,地址栏的变化。点击后做一个浏览器刷新确实获得页面。因此,一些在角度正在改变地址栏而不是触发负载???

I have an index of objects returned from search. The template has an ng-repeat where the item's URL is constructed from data in the model but in the final markup the "a" tag does not work. The ng-href and href are correct, the URL bar changes when the link is clicked but the page does not load. Doing a browser refresh after the click does get the page. So something in Angular is changing the URL bar but not triggering a load???

无法使这部再现一个的jsfiddle。随着模拟查询负载静态数据的工作的jsfiddle即使最终的标记看起来完全相同。

Can't make this reproduce in a jsfiddle because the problem seems to be in loading the json into the template after a $resource.query() function, which I can't do from a jsfiddle. With a simulated query loading static data the jsfiddle works even though the final markup looks identical.

在AngularJS模板看起来是这样的:

The AngularJS template looks like this:

<div ng-controller="VideoSearchResultsCtrl" class="row-fluid">
  <div class="span12" >
    <div class="video_thumb" ng-repeat="video in videos">
      <p>
        <a ng-href="/guides/{{video._id}}" data-method="get">
          <img ng-src="{{video.poster.large_thumb.url}}">
        </a>
      </p>
    </div>
  </div>
</div>

结果看起来很好,并产生下列最终的标记:

The results look fine and produce the following final markup:

<div ng-controller="VideoSearchResultsCtrl" class="row-fluid ng-scope">
  <div class="span12">
    <!-- ngRepeat: video in videos --><div class="video_thumb ng-scope" ng-repeat="video in videos">
      <p>
        <a ng-href="/guides/5226408ea0eef2d029673a80" data-method="get" href="/guides/5226408ea0eef2d029673a80">
          <img ng-src="/uploads/video/poster/5226408ea0eef2d029673a80/large_thumb_2101146_det.jpg" src="/uploads/video/poster/5226408ea0eef2d029673a80/large_thumb_2101146_det.jpg">
        </a>
      </p>
    </div><!-- end ngRepeat: video in videos -->
  </div>
</div>

控制器code是:

The controller code is:

GuideControllers.controller('VideoSearchResultsCtrl', ['$scope', '$location', 'VideoSearch',
    function($scope, $location, VideoSearch) {
        $scope.videos = VideoSearch.query({ namespace: "api", resource: "videos", action: 'search', q: $location.search().q });
    }
]);

使用AngularJS 1.2- rc.3。我使用的是NG-点击普通的旧的onclick报复静态URL加载的页面也尝试过,但从来没有点击触发code。 BTW此页面上的静态无棱角环节做工作,使菜单栏和注销工作。

Using AngularJS 1.2-rc.3. I've also tried using an ng-click and regular old onclick to get a page loaded even with static URL but the clicks never trigger the code. BTW static non-angular links on this page do work, so the Menu Bar and Sign Out work.

我做了什么错在这里,或这是AngularJS中的错误?

What have I done wrong here or is this a bug in AngularJS?

推荐答案

从邮件列表中我得到了一个答案:

From the mailing list I got an answer:

你有任何机会配置您的$ locationProvider到
  html5Mode?如果是的话,这将导致您的问题。你可以迫使它
  要经常去的网址加入目标=_自我到您的标记。给
  它一试。

Have you by any chance configured your $locationProvider to html5Mode? If yes this would cause your problems. You could force it to always go to the url by adding target="_self" to your tag. Give it a shot.

我已经配置为使用HTML5所以添加目标=_自我来解决了这一问题的标记。仍在研究为什么这个工作的。

I had configured to use HTML5 so adding the target="_self" to the tag fixed the problem. Still researching why this works.

这篇关于AngularJS&LT; A&GT;不工作的标签链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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