从json文件加载数据

loading data from json files

本文关键字:数据 加载 文件 json      更新时间:2023-09-26

我正在想办法。如果我想从我的angular应用程序中的本地文件加载JSON数据,我有没有办法在angular中包含或读取文件,或者我需要使用一些文件API从文件中读取并将对象存储在数组中。ty

您可以使用$http从json文件加载json数据

var name = angular.module("app", []);
name.controller("ctrlu", ['$scope','$http', function($scope, $http)
        {    
            $http.get('js/data.json').success (function(data){
                $scope.guitarVariable = data;
        });
        }]
);

注意:您不需要在index.html页面

中包含(引用)json文件