Javascript 将值传递到$mdDialog控制器
我试图使用$mdDialog将值从控制器传递到服务。var id具有该值,但当我转到testService时,该值不存在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
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中输入代码时,这是一个输入错误。在我的代码中,我没有输入错误。