【问题标题】:How to view the image in fullscreen using ng-repeat?如何使用 ng-repeat 全屏查看图像?
【发布时间】:2019-07-17 19:50:23
【问题描述】:

我期待像 https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal_img 这样的东西,但在使用 ng-repeat 时它似乎不起作用

angular.module('selectExample', [])
  .controller('ExampleController', ['$scope', function($scope) {
 
    $scope.register = {
      regData: {
        branch: {},
      },
      names: [{
        name:"narquois",
        image:[
        "https://picsum.photos/200",
        "https://picsum.photos/200/300/"]
        
        }],
    };

  }]);
img{
width:70px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<table id="example" width="100%">
		
   
       <tr ng-repeat="person in register.names">
         <td align="center">{{ person.name }}</td>
         <td align="center"><img ng-repeat="image in person.image" ng-src="{{ image}}"></td>
       </tr>
   
</table> 
</div>

【问题讨论】:

  • 如果你想让你的图像出现在一个模态对话框中,你需要代码来做到这一点。 ng-repeat 仅用于重复项目。
  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:How to create a Minimal, Complete, and Verifiable example

标签: javascript html css angularjs


【解决方案1】:

请运行以下代码。 希望能解决你的问题。

angular.module('selectExample', [])
  .controller('ExampleController', ['$scope', function($scope) {

    $scope.register = {
      regData: {
        branch: {},
      },
      names: [{
        name: "narquois",
        image: [{
          'image': "https://picsum.photos/200",
          'flag': false
        }, {
          'image': "https://picsum.photos/200/300/",
          'flag': false
        }]

      }],
    };
    $scope.getBig = function(key, value) {
      $scope.register.names[0].image[key].flag = true;
    }
    $scope.close = function(key, value) {
      $scope.register.names[0].image[key].flag = false;
    }
  }]);
.imgSmall {
  width: 70px;
}


/* The Modal (background) */

.modal {
  /* Hidden by default */
  position: fixed;
  /* Stay in place */
  z-index: 1;
  /* Sit on top */
  padding-top: 100px;
  /* Location of the box */
  left: 0;
  top: 0;
  width: 100%;
  /* Full width */
  height: 100%;
  /* Full height */
  overflow: auto;
  /* Enable scroll if needed */
  background-color: rgb(0, 0, 0);
  /* Fallback color */
  background-color: lightblue;
}


/* Modal Content (image) */

.modal-content {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
}


/* Caption of Modal Image */

#caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}


/* Add Animation */

.modal-content,
#caption {
  -webkit-animation-name: zoom;
  -webkit-animation-duration: 0.6s;
  animation-name: zoom;
  animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
  from {
    -webkit-transform: scale(0)
  }
  to {
    -webkit-transform: scale(1)
  }
}

@keyframes zoom {
  from {
    transform: scale(0)
  }
  to {
    transform: scale(1)
  }
}


/* The Close Button */

.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
  cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
  <table id="example" width="100%">


    <tr ng-repeat="person in register.names">
      <td align="center">{{ person.name }}</td>
      <td align="center" ng-repeat="(key,image) in person.image"><img class="imgSmall" ng-src="{{image.image}}" ng-click="getBig(key,image)">
        <div ng-show="image.flag" id="myModal" class="modal">
          <span class="close" ng-click="close(key,image)">&times;</span>
          <img class="modal-content" ng-src="{{image.image}}" id="img01">
          <div id="caption"></div>
        </div>
      </td>
    </tr>
  </table>

</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-03
    • 2018-05-09
    • 2014-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-02
    相关资源
    最近更新 更多