gpt4 book ai didi

javascript - 如何在 Angularjs $state.go 中发送参数?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:25 26 4
gpt4 key购买 nike

我正在开发 AngularJS 应用程序。我正在尝试将 $state.go 中的值发送到不同的状态。我正在尝试如下。

这是我的状态:

$stateProvider
.state('Registration.OTPVerification', {
url: '/RegistrationOTPVerification',
templateUrl: 'Registration/RegistrationOTP.html',
controller: 'RegistrationOTPVerification'
});

我正在尝试如下。

var customerid = response.data.ID;
var OTP = response.data.OTP;
$state.go('Registration.OTPVerification', customerid,OTP);

我正在尝试在下面的 Controller 中接收参数。

(function () {
angular.module('RoslpApp').controller('RegistrationOTPVerification', ['$scope', '$http', '$translatePartialLoader', '$translate', '$state', function ($scope, $http, $translatePartialLoader, $translate, $state, $stateParams) {
var customerid = $stateParams.customerid;
var OTP = $stateParams.OTP;
alert(customerid);
}]);
})();

我无法接收参数。任何帮助,将不胜感激。谢谢。

最佳答案

您需要将它们作为params,以便能够通过state 发送它们。像这样:

$stateProvider
.state('Registration.OTPVerification', {
url: '/RegistrationOTPVerification',
params: {
customerid: null,
OTP: null
},
templateUrl: 'Registration/RegistrationOTP.html',
controller: 'RegistrationOTPVerification'
});

现在,您可以像下面这样使用 $state.go:

$state.go('Registration.OTPVerification', {
customerid: 123,
OTP: 2323
});

最后,您可以使用 $stateParams.customerid$stateParams.OTP 访问它们,但请确保您有 $stateParams就像注入(inject)了 $state$translate 一样注入(inject)。

关于javascript - 如何在 Angularjs $state.go 中发送参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43276855/

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