AngularJS: How to load JSON data onto a scope variable

后端 未结 5 1466
南笙
南笙 2021-02-07 21:46

I\'m creating a personal website where I can keep updating content without having to manipulate the HTML. I\'m trying to achieve this by simply loading and updating

5条回答
  •  天涯浪人
    2021-02-07 22:04

    var myapp=angular.module('mainApp',[]);
    myapp.controller('mainController',function($scope,$http){
        $scope.content = null;
        $http({method: 'GET', url: 'mainContent.json'}).
            success(function(data, status, headers, config) {
                $scope.contents=data;
            }).error(function(data, status, headers, config) {          
        });
    });
    

    Published in Web Server and added Mime type for .json. It worked.

提交回复
热议问题