javascript - 为什么 html5lightbox 不适用于 Angular ?

标签 javascript jquery html angularjs lightbox

我使用 html5lightbox 在灯箱中打开图像和 pdf 文件。现在我添加了 angular.js,当点击一个链接时,它会将我带到另一个页面而不是在灯箱中打开它

var app =  angular.module('MyApp', []);

var tiles =
[
    {
        class: "fileTile",
        link: "images/9-credit-1.jpg",
        header: "ToDo List",
        content: "PDF File contains information about SAP sales and customers"
    },
    {
        class: "videoTile",
        link: "https://www.youtube.com/watch?v=Nfq3OC6B-CU",
        header: "Fiori Tutorial",
        content: "This Video contains information about SAP sales and customers"
    },
    {
        class: "fileTile",
        link: "images/canberra_hero_image_JiMVvYU.jpg",
        header: "A Random Image",
        content: "PDF File contains information about SAP sales and customers"
    },
    {
        class: "fileTile",
        link: "images/national-basketball-association-scoring-big-with-real-time-statistics-and-sap-hana.pdf?iframe=true",
        header: "National Basketboal Team",
        content: "PDF File contains information about SAP sales and customers"
    }
];


  app.controller("DisplayController", function($scope, $http){
     $scope.tiles = tiles;
  });

我该怎么做才能使 html5lightbox 正常工作???

最佳答案

使用angular-bootstrap-lightbox .简直太棒了。

这是工作 Plunker

html

<ul ng-controller="GalleryCtrl">
  <li ng-repeat="image in images">
    <a ng-click="openLightboxModal($index)">
      <img ng-src="{{image.thumbUrl}}" class="img-thumbnail">
    </a>
  </li>
</ul>

JS( Controller )

angular.module('app').controller('GalleryCtrl', function ($scope, Lightbox) {
  $scope.images = [
    {
      'url': '1.jpg',
      'caption': 'Optional caption',
      'thumbUrl': 'thumb1.jpg' // used only for this example
    },
    {
      'url': '2.gif',
      'thumbUrl': 'thumb2.jpg'
    },
    {
      'url': '3.png',
      'thumbUrl': 'thumb3.png'
    }
  ];

  $scope.openLightboxModal = function (index) {
    Lightbox.openModal($scope.images, index);
  };
});

DEMO

关于javascript - 为什么 html5lightbox 不适用于 Angular ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36815993/

相关文章:

jquery - 我如何通过 jquery 和 ajax 替换图像(在 div 内)

jquery - 使用 JavaScript 动态伪元素 CSS

javascript - DataTables 问题 : VM9075 dataTables. min.js:24Uncaught TypeError: 无法设置未定义的属性 '_DT_CellIndex'

javascript - 是否可以从 numberFormat (NetSuite) 字段获取值并在代码中使用它?

Javascript 包括不在页面中稍后加载

javascript - 如何在 vue.js 中按字母和数字对表格进行排序?

html - 在高度为 100% 的 div 中垂直对齐

javascript - 超过 15 个 KML 图层在基于 Google map API 的页面上将不可见

JQuery - 小部件公共(public)方法

php - JQuery .post 不起作用,似乎没有加载帖子页面