0
我無法從我的控制器訪問$ routeParams值。
我的角度應用定義如下;
(function() {
'use strict';
var app = angular.module("rbApp", [
"ngAnimate", "ui.router", "ui.bootstrap", "ngMessages", "ngRoute", "common.services" ]);
app.config(["$stateProvider", "$urlRouterProvider", "$locationProvider", "$urlMatcherFactoryProvider", function ($stateProvider, $urlRouterProvider, $locationProvider, $urlMatcherFactoryProvider) {
$urlMatcherFactoryProvider.caseInsensitive(true);
$urlMatcherFactoryProvider.strictMode(false);
$urlRouterProvider.otherwise("/");
$stateProvider
.state("confirmemail", {
url: "/Confirm_Email?userId",
templateUrl: "ceForm.html",
controller: "ceController as ceVm"
});
}]);
})();
我的控制器是;
(function() {
"use strict";
angular
.module("common.services")
.controller("ceController", ["$scope", "$state", "$routeParams", "pageContentService", "accountService", "sharedServices", ceController]);
function ceController($scope, $state, $routeParams, pageContentService, accountService, sharedServices) {
var vm = this;
vm.emailConfirmed = false;
console.log("confirmEmail userId: ", $routeParams.userId);
if ($routeParams.userId) {
.
.
.
}
};
})();
但是當我在URL傳似http://example.com?userId=9daa2c41$ routeParams.userId永遠是不確定的。
您正在使用ui路由器,因此正確的提供程序是'$ stateParams'。 '$ routeParams'屬於'ngRoute'模塊。我不會推薦混合兩個 – Phil
謝謝@Phil,解決了我的問題。 –