gpt4 book ai didi

javascript - AngularJS - 将可选参数传递给模态

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:14:56 26 4
gpt4 key购买 nike

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

Controller A(触发器):

$modal.open({
templateUrl: 'UploadPartial.html',
controller: 'photos.uploadCtrl',
resolve: {
preselectedAlbum: function preselectedAlbum() {
return angular.copy($scope.selectedAlbum);
}
}
});

Controller B(模态):

app.controller('photos.uploadCtrl', [
'$scope',
'$modalInstance',
'$injector',
function uploadCtrl($scope, $modalInstance, $injector) {
if ($injector.has('preselectedAlbum')) {
console.log('happy'); // I want this to work, but $injector doesn't find it
} else {
console.log('sad'); // Always gets here instead :(
}
}
]);

注意:当我将 preselectedAlbum 作为依赖项时,它会起作用,但是当我没有明确传递它时,我会收到错误。我希望它是可选的。

最佳答案

给模态 Controller 附加一个值

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

关于javascript - AngularJS - 将可选参数传递给模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25046961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com