Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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
Javascript AngularJS-将可选参数传递给Modal_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS-将可选参数传递给Modal

Javascript AngularJS-将可选参数传递给Modal,javascript,angularjs,Javascript,Angularjs,如何将可选参数传递给angularJS模式?这是我的密码: 控制器A(触发器): 控制器B(模态): 注意:当我把preselectedAlbum作为一个依赖项时,它可以工作,但是当我没有显式地传递它时,就会得到错误。我希望它是可选的。除了解析:,您还可以通过作用域:将值传递给模态控制器 $scope.preselectedAlbum = angular.copy($scope.selectedAlbum); $modal.open({ templateUrl: 'UploadPartia

如何将可选参数传递给angularJS模式?这是我的密码:

控制器A(触发器):

控制器B(模态):


注意:当我把
preselectedAlbum
作为一个依赖项时,它可以工作,但是当我没有显式地传递它时,就会得到错误。我希望它是可选的。

除了
解析:
,您还可以通过
作用域:
将值传递给模态控制器

$scope.preselectedAlbum = angular.copy($scope.selectedAlbum);

$modal.open({
  templateUrl: 'UploadPartial.html',
  controller: 'photos.uploadCtrl',
  scope: $scope,
});
然后在模态控制器中:

function uploadCtrl($scope, $modalInstance) {
  if ($scope.preselectedAlbum) {
    console.log('happy');
  } else {
    console.log('sad');
  }
}

示例plunker:

将值附加到模式控制器

angular.module('app')
    .controller('TestCtrl',TestCtrl)
    .value('noteId', null); // optional param

我认为这是不可能的,injected
$injector
服务对
解析:
对象一无所知。当不需要伪函数时,可能必须传递它。或者通过
$scope
对象更改传递
预选album
的方式。@runTarm您可以演示如何通过$scope对象将信息传递给控制器吗?如果可能的话,这对我来说是完美的,但我不知道如何对它进行更改,以便在正在打开的新控制器中保持不变。
function uploadCtrl($scope, $modalInstance) {
  if ($scope.preselectedAlbum) {
    console.log('happy');
  } else {
    console.log('sad');
  }
}
angular.module('app')
    .controller('TestCtrl',TestCtrl)
    .value('noteId', null); // optional param