Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angular JS中使用$Routeparams从json文件检索数据_Javascript_Jquery_Angularjs_Json - Fatal编程技术网

Javascript 如何在angular JS中使用$Routeparams从json文件检索数据

Javascript 如何在angular JS中使用$Routeparams从json文件检索数据,javascript,jquery,angularjs,json,Javascript,Jquery,Angularjs,Json,我面临使用$routeparams检索数据的问题,我将说明我的问题 /正在检索要重定向的URL/ /正在检索要重定向的URL/ 这就是我试图获取数据的方式,但当我控制台它时,$routeparams拥有数据->它拥有需要的url 但当我连接到“json url”时,它在控制台中显示“加载资源失败:服务器响应状态为404(未找到)”和“未定义” 我正在共享我的app.js app.js 我的菜单.html 当我点击菜单中的特定链接时,它会动态重定向到相关的json文件 <ul id="sub

我面临使用$routeparams检索数据的问题,我将说明我的问题

/正在检索要重定向的URL/

/正在检索要重定向的URL/

这就是我试图获取数据的方式,但当我控制台它时,$routeparams拥有数据->它拥有需要的url 但当我连接到“json url”时,它在控制台中显示“加载资源失败:服务器响应状态为404(未找到)”和“未定义”

我正在共享我的app.js

app.js 我的菜单.html 当我点击菜单中的特定链接时,它会动态重定向到相关的json文件

<ul id="submenu-2" class="collapse" >
                            <span ng-repeat="item in itemDetails">
                            <li><a href="#base-product?{{item.path}}" > {{item.title}}</a></li>
                            </span>

                        </ul>
我编写了一个工厂,从json文件(action.json)中获取数组值


帮我解决这个问题。.提前谢谢

您的url参数错误,您不需要使用“?”标记。换成

看法


您的url参数错误,不需要使用“?”标记。换成

看法


@ManikandanVelayutham:-这是语法。。如果我删除“?”重定向和路由图将无法工作@ManikandanVelayutham:-这是语法。。如果我删除“?”重定向和路由图将无法工作!!!
App.config(['$routeProvider',function($routeProvider, $routeParams) {

            $routeProvider

    .when('/base-product/:json_url?', {
                    templateUrl :'templates/base_product.html',
                    controller  :'BaseProductController'
                })      
<ul id="submenu-2" class="collapse" >
                            <span ng-repeat="item in itemDetails">
                            <li><a href="#base-product?{{item.path}}" > {{item.title}}</a></li>
                            </span>

                        </ul>
[

   {
      "title":"View",
      "path":"actions/view.json",
      "urlpath":"view?segment=view",
      "apiPath":"api/view",
      "methodType":"post"

   },

    {
       "title":"Add",
      "path":"actions/add.json",
      "urlpath":"view?segment=add",
      "apiPath":"api/add",
      "methodType":"post"

   },

]
App.factory('itemsFactory', ['$http', function($http){
  var itemsFactory ={
    itemDetails: function() {
      return $http(
      {
        url: "api-data/action.json",
        method: "GET",
      })
      .then(function (response) {
        return response.data;
        });
      }
    };
    return itemsFactory;

}]);


App.controller('SidenavItems_controller', ['$scope', 'itemsFactory', function($scope, itemsFactory){

    console.log("Loading json array name is working fine and tested in console")
  var promise = itemsFactory.itemDetails();

    promise.then(function (data) {
        $scope.itemDetails = data;
        console.log(data);
    });
    $scope.select = function(item) {
      $scope.selected = item;
    }
    $scope.selected = {};
}]);
<li><a href="#base-product/{{item.path}}" > {{item.title}}</a></li>
.when('/base-product/:json_url', {...}