【问题标题】:ng-click "id (factory)" going to new template but not shows img from specific idng-click "id (factory)" 转到新模板但不显示来自特定 id 的 img
【发布时间】:2015-10-16 14:04:30
【问题描述】:

我可以使用ng-click 转到id 位置(http://localhost:9000/#/info-serie/1),但没有显示id 的img,我尝试使用此信息http://jsfiddle.net/daSJ5/124/,但没有。

$scope.sliderImg = slider.getsliderImg();
$scope.go = function(id){
      $location.url('/info-serie/' + id);
};
//////////////// VIEW ONE //////////////////////////
<div ng-repeat="images in sliderImg" ng-click="go(images.id)">
    <img ng-src="{{images.img}}" alt="" class="img-carousel"/>
</div>
//////////////// VIEW TWO //////////////////////////
<img ng-src="{{images.img}}" alt=""/>

'use strict';

angular.module('appApp').factory('slider', function(){
        var sliderImg = [
                {
                    id  : 0,
                    img : "../../images/American-Horror-Story-season-4.jpg"
                },
                {
                    id  : 1,
                    img : "../../images/Defiance-season-3-2015.jpg"
                },
                {
                    id  : 2,
                    img : "../../images/Falling_Skies_poster_the_fianl_season.jpg"
                }
            ];

【问题讨论】:

标签: javascript angularjs-directive angularjs-scope angularjs-ng-repeat angularjs-service


【解决方案1】:

我不确定我是否理解您的问题,但通过查看代码的一些评论

工厂需要返回一些东西(从您的服务的外观来看,您似乎刚刚创建了一个变量。

还有一件事是网址。如果您想更改 url 没关系,但如果您想更改页面而不仅仅是 url,您可能应该尝试 $location.path('/info-serie/' + id)。

希望对你有帮助

【讨论】:

  • 是的,退货。 return { getsliderImg: function() { return sliderImg; } };
  • 我有一个滑块,如果我点击任何 img,它会转到 id,并且“它必须显示 id img”。 click --> go to id --> id有img(显示)。
猜你喜欢
  • 2021-07-02
  • 2016-10-06
  • 2012-06-07
  • 1970-01-01
  • 1970-01-01
  • 2021-06-25
  • 2021-03-24
  • 1970-01-01
  • 2013-08-10
相关资源
最近更新 更多