小编iam*_*ash的帖子

AngularJS在控制器中多次调用HTTP

我正在使用Angular开发一个页面,并在我的控制器中有一个init()方法.代码如下:

var filtersController = ['$scope', '$http', function ($scope, $http) {
    $scope.init = function () {
        $http({
            method: 'GET',
            url: '/json-tags-test',
            cache: true
        }).success(function (data, status, headers, config) {
                // this callback will be called asynchronously
                // when the response is available
        }).error(function (data, status, headers, config) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
        });
   };
}];
Run Code Online (Sandbox Code Playgroud)

它只是对一个简单的JSON文件的调用.

我的HTML如下:

<div class="container main-frame" ng-app="projectsApp" ng-controller="filtersController" ng-init="init()">
</div>
Run Code Online (Sandbox Code Playgroud)

出于某种原因,每次加载页面时,此get调用都会调用两次.这是标准行为吗?

非常感谢,

短跑

在此输入图像描述

json http angularjs

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

angularjs ×1

http ×1

json ×1