[英]How to retrieve data from a json file using $Routeparams in angular JS
[英]How to get parameters value using $routeParams from URL in angular js?
我正在使用Angularjs,遇到了奇怪的问题,无法使用$ routeParams从URL获取参数值。
var MyApp = angular.module('testAngularApp', ['ngRoute','ngResource'])
.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/', {
when('/updateUser/:id', {
templateUrl: 'Pages/User/Edit.html',
controller: 'UpdateUserCtrl'
})
}]);
控制者
angular.module('testAngularApp').
controller('UpdateUserCtrl', ['$scope', 'updateUserService', '$http','$route', '$routeParams', function ($scope, updateUserService, $routeParams,$route, $http) {
$scope.testV = "Update User Ctrl";
console.log("hello");
$scope.params1 = $routeParams.id;
console.log($routeParams.id ); //i am getting undefined
console.log($scope.params1); //i am getting undefined
var check = $routeParams['id'];
console.log(check); //i am getting undefined
}]);
我认为service
的顺序是错误的。 尝试如下更改
controller('UpdateUserCtrl', ['$scope', 'updateUserService','$route','$http' '$routeParams',
function ($scope, updateUserService,$route, $http, $routeParams)
$routeParams
将从URL到您的控制器的参数列表
您定义的函数定义错误。 它的定义顺序应与我们为局部变量创建的顺序相同。
controller('UpdateUserCtrl',
['$scope', 'updateUserService', '$http','$route','$routeParams',
function ($scope, updateUserService, $http,$route,$routeParams ) {
// your Script goes Here.
console.log($routeParams.id);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.