angularjs中的RouteRAM不工作
我对angularJs是新手。我正在创建一个应用程序,其中我在URL中传递了用户ID,然后尝试使用Routeparam在Js文件中获取ID,但它不起作用。我正在使用MVC 4和angularjs。 请看我的密码 我的URL/Home/GetUserInformation?userID=44。我想在下面的代码中使用userIDangularjs中的RouteRAM不工作,angularjs,Angularjs,我对angularJs是新手。我正在创建一个应用程序,其中我在URL中传递了用户ID,然后尝试使用Routeparam在Js文件中获取ID,但它不起作用。我正在使用MVC 4和angularjs。 请看我的密码 我的URL/Home/GetUserInformation?userID=44。我想在下面的代码中使用userID var userInformationApp = angular.module('UserInformationApp', ['ngResource']) .co
var userInformationApp = angular.module('UserInformationApp', ['ngResource'])
.config(function config($routeProvider, $stateProvider)
{
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider.
when('/Home/GetUserInformation?userID=:ID',
{
templateUrl: "UserInformation.cshtml",
controller: "UserInformationController"
})
angular.module('UserInformationApp', []).controller("UserInformationController", function ($scope, $routeParams, $http)
{
debugger;-----// My debugger is not hitting when I used routeParams.If I remove Route params Then it is working fine but route params then come undefined.
$scope.saveNote = function ()
{
$scope.newNote = $scope.userNote;
$scope.intialValue = true;
$scope.record = $routeParams.ID;///// This I saw in net to get the ID or information from the URL in angular js.
}
});
当我使用RouteParams时,我的调试器没有运行。有两种方法可以获取url中的参数:使用$RouteParams和手动 角度法 angular中的正常方式是$routeParams: 现在它在控制器中可用:
$scope.record = $routeParams.userid
一些教程
查询字符串
或者,您也可以手动获取查询字符串中的参数
如果您知道参数的名称:
$location.search().yourparam
如果您有任意数量的参数,但您不知道它们的名称,例如初始化应用程序的设置:
var queryString = $location.absUrl().match(/^[^?]+\??([^#]*).*$/)[1];
var items = queryString.split("&");
var params = {};
for (var i = 0, l = items.length; i < l; i++) {
var temp = items[i].split("=");
if (temp[0]) {
if (temp.length < 2) {
temp.push("");
}
params[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
}
}
不工作。事实上,当我在控制器中使用$routeParam时,我的流中断。它没有进入控制器函数内部。在控制器声明中,您可以尝试更改'angular.module'UserInformationApp',[]'为angular.module'UserInformationApp'?我的流量中断不是错误消息。您也可以阅读文档
var queryString = $location.absUrl().match(/^[^?]+\??([^#]*).*$/)[1];
var items = queryString.split("&");
var params = {};
for (var i = 0, l = items.length; i < l; i++) {
var temp = items[i].split("=");
if (temp[0]) {
if (temp.length < 2) {
temp.push("");
}
params[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
}
}