Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度UI模式,避免模式范围更改反映在父范围中_Angularjs_Angular Bootstrap - Fatal编程技术网

Angularjs 角度UI模式,避免模式范围更改反映在父范围中

Angularjs 角度UI模式,避免模式范围更改反映在父范围中,angularjs,angular-bootstrap,Angularjs,Angular Bootstrap,我正在构建一个Angular应用程序,我想控制应用程序列表中我想在主页上显示的应用程序。有一个名为“管理应用程序”的部分,我可以在其中管理可见的应用程序 上面的例子解释了我想要实现的目标 我已将json格式的应用程序列表从父范围传递到模式实例。我想对其中一个字段进行更改,IsPublished 现在的问题是,每当我在模态的isPublished字段中进行更改时,它都会立即反映在父范围中。您可以看到应用程序在覆盖后的父作用域中被过滤 我想避免它。我只想在单击“保存/确定”按钮时反映对父范围的更改

我正在构建一个Angular应用程序,我想控制应用程序列表中我想在主页上显示的应用程序。有一个名为“管理应用程序”的部分,我可以在其中管理可见的应用程序

上面的例子解释了我想要实现的目标

我已将json格式的应用程序列表从父范围传递到模式实例。我想对其中一个字段进行更改,
IsPublished

现在的问题是,每当我在模态的isPublished字段中进行更改时,它都会立即反映在父范围中。您可以看到应用程序在覆盖后的父作用域中被过滤

我想避免它。我只想在单击“保存/确定”按钮时反映对父范围的更改


有什么方法可以做到这一点吗?

您需要一个源文件的深度副本使用angular.copy。这些更改直接反映到主屏幕,因为您将$scope.apps与$scope.items绑定,因此两者都引用到同一位置

angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $modal, $log) {

  $scope.items = ['item1', 'item2', 'item3'];

$scope.apps = [
   {

      "FileSystemObjectType":0,
      "Id":1,
      "ContentTypeId":"0x01008178C725CC128447AD122168CA03E484",
      "Title":"First App",
      "AppUrl":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"http://www.google.com",
         "Url":"http://www.google.com"
      },
      "AppIcon":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"https://unsplash.it/150/?random",
         "Url":"https://unsplash.it/150/?random"
      },
      "CanDelete":false,
      "IsPublished":false,
      "Priority":null,
      "ID":1,
      "Modified":"2015-03-04T15:44:36Z",
      "Created":"2015-02-26T05:24:00Z",
      "AuthorId":9,
      "EditorId":9,
      "OData__UIVersionString":"1.0",
      "Attachments":false,
      "GUID":"5a3e620d-461c-4663-8837-36bfd2967dad"
   },
   {

      "FileSystemObjectType":0,
      "Id":2,
      "ContentTypeId":"0x01008178C725CC128447AD122168CA03E484",
      "Title":"App 2",
      "AppUrl":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"http://microsoft.com",
         "Url":"http://microsoft.com"
      },
      "AppIcon":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"https://unsplash.it/150/?random",
         "Url":"https://unsplash.it/150/?random"
      },
      "CanDelete":true,
      "IsPublished":false,
      "Priority":null,
      "ID":2,
      "Modified":"2015-03-04T15:44:36Z",
      "Created":"2015-02-26T05:25:11Z",
      "AuthorId":9,
      "EditorId":9,
      "OData__UIVersionString":"1.0",
      "Attachments":false,
      "GUID":"e919eb66-0f2b-4ed4-aad9-3b64400bf09a"
   },
   {

      "FileSystemObjectType":0,
      "Id":3,
      "ContentTypeId":"0x01008178C725CC128447AD122168CA03E484",
      "Title":"App 3",
      "AppUrl":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"http://google.com",
         "Url":"http://google.com"
      },
      "AppIcon":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"https://unsplash.it/150/?random",
         "Url":"https://unsplash.it/150/?random"
      },
      "CanDelete":true,
      "IsPublished":true,
      "Priority":0,
      "ID":3,
      "Modified":"2015-03-04T15:44:36Z",
      "Created":"2015-02-26T08:06:23Z",
      "AuthorId":9,
      "EditorId":9,
      "OData__UIVersionString":"1.0",
      "Attachments":false,
      "GUID":"07a63d11-fe94-4fc2-95fc-b7ddf16f160a"
   },
   {

      "FileSystemObjectType":0,
      "Id":4,
      "ContentTypeId":"0x01008178C725CC128447AD122168CA03E484",
      "Title":"Test1",
      "AppUrl":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"http://www.attini.com",
         "Url":"http://www.attini.com"
      },
      "AppIcon":{
         "__metadata":{
            "type":"SP.FieldUrlValue"
         },
         "Description":"https://unsplash.it/150/?random",
         "Url":"https://unsplash.it/150/?random"
      },
      "CanDelete":true,
      "IsPublished":true,
      "Priority":1,
      "ID":4,
      "Modified":"2015-03-04T15:44:36Z",
      "Created":"2015-02-27T03:58:37Z",
      "AuthorId":9,
      "EditorId":9,
      "OData__UIVersionString":"1.0",
      "Attachments":false,
      "GUID":"9375eff9-4101-4c1f-ad85-bedc484b355f"
   }
];

  $scope.open = function (size) {

    var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      size: size,
      resolve: {
        items: function () {
          return $scope.apps;
        }
      }
    });

    modalInstance.result.then(function (items) {
      $scope.apps = angular.copy(items);
    }, function () {
      $log.info('Modal dismissed at: ' + new Date());
    });
  };
});

// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.

angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {

  $scope.items = angular.copy(items);
  $scope.selected = {
    item: $scope.items[0]
  };

  $scope.ok = function () {
    $modalInstance.close($scope.items);
  };

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});

工作

伙计,你真了不起。谢谢你。。对我来说是一次很好的学习:-)很高兴能帮助你:-)