加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 无法将范围传递给角度对话框

发布时间:2020-12-17 09:57:49 所属栏目:安全 来源:网络整理
导读:我正在使用Angular显示图像列表. 单击图像时,我想显示带有图像和更多信息的对话框. 因此,当打开模态时,我需要传递范围,或者至少是图像. 注意:我使用ngDialog作为弹出窗口. application.controller('ImageController',function ImageController($scope,Image
我正在使用Angular显示图像列表.

单击图像时,我想显示带有图像和更多信息的对话框.

因此,当打开模态时,我需要传递范围,或者至少是图像.

注意:我使用ngDialog作为弹出窗口.

application.controller('ImageController',function ImageController($scope,ImageService,ngDialog) {

    $scope.model = {
      images: [],loading: false
    }

    var load = function () {
      $scope.model.loading = true;
      ImageService.GetList($scope.model.pages.instagram)
        .success(function (data,status,headers,config) {
          $scope.model.images = $scope.model.images.concat(data.Images)
        })
        .error(function (data,config) { })
        .finally(function () {
          $scope.model.loading = false
        });;
    }

    $scope.open = function (image) {
      ngDialog.open({
        template: '<p>my template {{image.Key}} </p>',plain: true,scope: $scope
      });
    };


    load();

  });

  <div data-ng-app="Application" data-ng-controller="ImageController">
    <div data-ng-repeat='image in model.images'>
    <img src="{{image.Url}}" alt="" data-ng-click="open(image)"/>
  </div>

显示图像并在点击时打开对话框…

但是,不知何故,我无法访问模板内的范围.

以下作品:

$scope.open = function (image) {
      ngDialog.open({
        template: '<p>my template' + image.Key + '</p>',plain: true
      });
    };

但这不起作用:

$scope.open = function (image) {
      ngDialog.open({
        template: '<p>my template {{image.Key}} </p>',scope: $scope
      });
    };

有谁知道为什么?

我无法弄清楚这一点.

将您的open方法更改为以下..
$scope.open = function (image) {
      var newScope = $scope.$new();
      newScope.image = image;
      ngDialog.open({
        template: '<p>my template {{image.Key}} </p>',scope: newScope
      });
    };

这应该工作……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读