没有使用angular.js获取查询字符串值


Not getting query string value using angular.js

我有一个这样的URL http://localhost/phpdemo/edit_data.php?edt_id=1。这里我需要查询字符串的值是1。通过使用Angular.js,我在浏览器的控制台中得到了以下输出:

id is : Object {}

我的代码如下:

update.js:

var app=angular.module("edit_data", []);
app.controller("updateController",function($scope,$http,$location){
    $scope.errors = [];
    $scope.msgs = [];
    var id=$location.search();
    console.log("id is :",id);
    $http.get('js/edit.php',{"user_id":$location.hash()}).success(function(response){
        console.log('response',response);
    });
    $scope.update_data=function(){
        $http.post('js/update.php',{"first_name":$scope.first_name,"last_name":$scope.last_name,"city":$scope.city}
        ).success(function(data, status, headers, config){
            if(data.msg!=''){
            $scope.msgs.push(data.msg);
            }else{
                $scope.errors.push(data.error);
            }
        }).error(function(data, status) { // called asynchronously if an error occurs
               // or server returns response with an error status.
              $scope.errors.push(status);
        });
    }
});

请帮我解决这个问题

$location.search()将返回一个键值对的对象,与查询字符串相同。没有值的键只是作为true存储在对象中。在本例中,对象将是:

var id=$location.search().edt_id;

位置服务搜索小概要

搜索(搜索、[paramValue]);这个方法是getter/setter。

在不带任何参数的情况下返回当前url的搜索部分(作为对象)。

使用参数调用时更改搜索部分并返回$location

// given url http://example.com/#/some/path?foo=bar&baz=xoxo
var searchObject = $location.search();
// => {foo: 'bar', baz: 'xoxo'}
// set foo to 'yipee'
$location.search('foo', 'yipee');
// $location.search() => {foo: 'yipee', baz: 'xoxo'}

这个$location.search();返回一个数组,所以

console.log("id is :",id[0]);

你能试一下吗?

更新:

$location.search()['edt_id']

它必须返回值1