I have an index of objects returned from a search. The template has ng-repeat, where the URL of the element is created from the data in the model, but the tag "a" does not work in the final markup. Ng-href and href are correct, the URL bar changes when the link is clicked, but the page does not load. Performing a browser refresh after a click gives you a page. So, something in Angular is changing the URL string, but not causing the load.
It is not possible to make this play in jsfiddle because the problem is loading json into the template after the $ resource.query () function, which I cannot do from jsfiddle. With a simulated query loading static data, jsfiddle works, although the final markup looks the same.
AngularJS template is as follows:
<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 great and produce the following final markup:
<div ng-controller="VideoSearchResultsCtrl" class="row-fluid ng-scope"> <div class="span12"> <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> </div> </div>
Controller Code:
GuideControllers.controller('VideoSearchResultsCtrl', ['$scope', '$location', 'VideoSearch', function($scope, $location, VideoSearch) { $scope.videos = VideoSearch.query({ namespace: "api", resource: "videos", action: 'search', q: $location.search().q }); } ]);
Using AngularJS 1.2-rc. 3. I also tried using ng-click and the plain old onclick to get a page loaded even with a static url, but clicks never run the code. BTW static non angular links on this page work, so menus and outputs work.
What have I done wrong here or is this a bug in AngularJS?