Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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 将值传递到$mdDialog控制器_Javascript_Angularjs - Fatal编程技术网

Javascript 将值传递到$mdDialog控制器

Javascript 将值传递到$mdDialog控制器,javascript,angularjs,Javascript,Angularjs,我试图使用$mdDialog将值从控制器传递到服务。var id具有该值,但当我转到testService时,该值不存在 module.controller('viewTestController', function ($scope, $routeParams, $mdDialog, testService) { var self = this; self.$onInit = function () { self.test = function () { var id

我试图使用$mdDialog将值从控制器传递到服务。var id具有该值,但当我转到testService时,该值不存在

module.controller('viewTestController', function ($scope, $routeParams, $mdDialog, testService) {
var self = this;
self.$onInit = function () {
    self.test = function () {
        var id = $scope.$parent.key;
        console.log(id);

        $mdDialog.show(
             locals: { dataToPass: id },
             templateUrl: '/test.html',
             title: "Test",
             clickOutsideToClose: true,
             scope: $scope,
             preserveScope: true,
             controller: function ($scope) {

                 $scope.finalizeTest = function (dataToPass) {
                     testService.finalizeTest(dataToPass);
                     $mdDialog.cancel();
                 };
             }
         });
    };
} 
});

您必须将
locals
属性直接传递到控制器函数中,如:

$mdDialog.show(
    locals: { dataToPass: id },
    templateUrl: '/test.html',
    title: "Test",
    clickOutsideToClose: true,
    scope: $scope,
    preserveScope: true,
    controller: function ($scope, $mdDialog, dataToPass) {
        $scope.finalizeTest = function () {
            testService.finalizeTest(dataToPass);
            $mdDialog.cancel();
        };
    }
});

您必须将
locals
属性直接传递到控制器函数中,如:

$mdDialog.show(
    locals: { dataToPass: id },
    templateUrl: '/test.html',
    title: "Test",
    clickOutsideToClose: true,
    scope: $scope,
    preserveScope: true,
    controller: function ($scope, $mdDialog, dataToPass) {
        $scope.finalizeTest = function () {
            testService.finalizeTest(dataToPass);
            $mdDialog.cancel();
        };
    }
});

你犯了一个打字错误。Just correct=>locals:{dataToPass:id}您犯了一个打字错误。Just correct=>locals:{dataToPass:id}谢谢。当我在stockoverflow中输入代码时,这是一个输入错误。在我的代码中没有输入错误。谢谢。当我在stockoverflow中输入代码时,这是一个输入错误。在我的代码中,我没有输入错误。