AngularJS将数据传递给uibModal

时间:2018-06-05 09:57:02

标签: angularjs angularjs-scope angular-ui-bootstrap

我想将一个对象从我的视图传递给我的模态,这个对象是" upFile"属性。但不幸的是,在我的观点层面没有显示任何内容,我可能对范围管理不善。

//来自我的控制器的方法

$scope.openConfirmGenerateErrorReport = function (upFile, reportType, parentSelector) {

    $scope.upFile = upFile;
    var parentElem = parentSelector ? 
            angular.element($document[0].querySelector('.modal-upload ' + parentSelector)) : undefined;
            var modalInstance = $uibModal.open({
                animation: $scope.animationsEnabled,
                ariaLabelledBy: 'modal-title',
                ariaDescribedBy: 'modal-body',
                templateUrl: 'modalContentConfirmGenerateReport.html',
                controller: 'ModalInstanceCtrl',
                size: "md",
                appendTo: parentElem,
                resolve: {
                    item : function (){
                        return $scope.upFile;
                    }
                }

            });

            modalInstance.result.then(function (paramFromDialog) {

            }, function () {
                $log.info('Modal dismissed at: ' + new Date());
            });

};

//我的TemplateUrl的控制器

UniversalPlugApplication.component('modalComponentConfirmGenerateReport', {
templateUrl: 'modalContentConfirmGenerateReport.html',
bindings: {
    resolve: '<',
    close: '&',
    dismiss: '&'
},
controller: function ($scope) {

    $scope.$onInit = function () {
        $scope.item = $rootScope.resolve.item;
    };
    $scope.ok = function () {
        $scope.close({$value: $rootScope.item});
    };
    $scope.cancel = function () {
        $scope.dismiss({$value: 'cancel'});
    };
}

});

// myModalInstance的控制器

UniversalPlugApplication.controller('ModalInstanceCtrl', function ($scope, $uibModalInstance, item) {

var $scope = this;
$scope.item = item;
$scope.ok = function () {
    $uibModalInstance.close($scope.item);
};
$scope.cancel = function () {
    $uibModalInstance.dismiss('cancel');
};

});

//从我的视图中提取:问题来自&#34; item.name&#34;变量返回NULL

<a id="linkDownloadErrorReport" ng-click="openConfirmGenerateErrorReport(upFile, 'Error report')" download>{{Error Report }}</a>

<script type="text/ng-template" id="modalContentConfirmGenerateReport.html">
    <div class="modal-header">
        <h3 class="modal-title" id="modal-title">Generation report request</h3>
    </div>
    <div class="modal-body" id="modal-body">
        <p>Do you also want to make a request to generate the integral report for <span ng-bind="item.name"></span> file ?</p>
    </div>
    <div class="modal-footer">
        <button class="btn btn-success" type="button" ng-click="$scope.ok()">OK</button>
        <button class="btn btn-default" type="button" ng-click="$scope.cancel()">Cancel</button>
    </div>
</script>

非常感谢你的帮助。

0 个答案:

没有答案