gpt4 book ai didi

javascript - 将值传递到 $mdDialog Controller

转载 作者:行者123 更新时间:2023-12-01 03:58:45 26 4
gpt4 key购买 nike

我正在尝试使用 $mdDialog 将值从 Controller 传递到服务。 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 属性直接传递到 Controller 函数中,例如:

$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();
};
}
});

关于javascript - 将值传递到 $mdDialog Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42388823/

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