Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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 如何将工厂注射到角度增压模式';谁的控制器?_Angularjs_Angular Ui Bootstrap - Fatal编程技术网

Angularjs 如何将工厂注射到角度增压模式';谁的控制器?

Angularjs 如何将工厂注射到角度增压模式';谁的控制器?,angularjs,angular-ui-bootstrap,Angularjs,Angular Ui Bootstrap,我想创建对话框以确认提交按钮。所以我使用的是AngularUI引导 这是我的主控制器代码: FrontEnd.controller('PostViewController',function($scope,$stateParams,PostFactory, $modal){ $scope.openConfirm = function(size) { var modalInstance = $modal.open({ animat

我想创建对话框以确认提交按钮。所以我使用的是AngularUI引导

这是我的主控制器代码:

FrontEnd.controller('PostViewController',function($scope,$stateParams,PostFactory, $modal){

    $scope.openConfirm = function(size) {

            var modalInstance = $modal.open({
                animation: true,
                templateUrl: 'ConfirmDialog.html',
                controller: 'ConfirmDialogController',
                size: size, 
                resolve: {
                    form: function () {
                            return $scope.form;
                        },
                    //tried with this line as well, but could not resolve error
                    PostFactory: "PostFactory"   
                }
            });

            modalInstance.result.then(function (response) {
                $scope.isSurveySubmitted = true;
                $scope.message = response.message;

                //$scope.selected = selectedItem;
              }, function () {
                console.log('Modal dismissed at: ');
            });
    };
});
这是我的ConfirmDialogController:

FrontEnd.controller('ConfirmDialogController', function($scope, $http, $modalInstance, form, PostFactory){

    $scope.ok = function () {

        PostFactory.SubmitSurvey(form).success(function(response){
            $modalInstance.close(response);
        }).success(function(response){
            $modalInstance.close(response);
        });
    };

    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
});
模态正确打开,没有错误。当我点击“取消”按钮时,它会像我预期的那样关闭模式。但当我单击确定时,它调用$scope.Ok(),但在控制台中抛出错误,并显示消息“PostFactory未定义”


那怎么办呢?谢谢您的帮助。

我想您可以使用
$modalInstance.open()

将工厂设置为新范围上的属性

var scope = $scope.$new();
scope.factory = PostFactory;
$modalInstance.open({
    // other stuff
    scope: scope
});
然后在YOU modal的控制器中引用$scope.factory


不确定它是否会弄乱其他任何东西,但值得一试。

那么,PostFactory的代码在哪里???这个错误非常明显,而且已经到了+1的程度。您可以告诉$modal要使用哪个作用域,这样您就可以在父控制器中使用相同的$scope,或者在PostViewController$scope上设置工厂,并将
{scope:$scope}
传递给modalInstance。[丹说什么]对不起。我的代码起作用了。这不起作用,因为我尝试使用PostFactory:resolve语句中的“PostFactory”。所以就去掉了那句话,它起了作用。顺便说一句,非常感谢你们两位给我更多关于如何将范围传递给modal的信息。干杯