为什么AngularJS发送双网络请求?

Ste*_*nes 1 angularjs

我在AngularJS单页面应用程序的控制器中有如下所示的代码.当这个页面运行并且我检查开发人员工具网络(在IE,Chrome和Firefox中)时,它总是显示2个成功的GET调用表,以及两个空的OPTIONS调用表.为什么有2个GET电话?这是正常的还是我在代码中做错了什么?另外,为什么它会发出2个OPTIONS调用?

"use strict";

app.controller('AdminController', function ($scope, $http)
{
    $scope.$parent.Title = "Admin";

    var url = $scope.$parent.BaseUrl + "Tables";
    $http.get(url)
        .then(function mySuccess(response)
        {
            $scope.MyTables = response.data;
        });
});
Run Code Online (Sandbox Code Playgroud)

Mic*_*oye 5

这在过去发生在我身上,问题是我在路线中定义了两次控制器:

.state('app.state', {
  url: '/state',
  controller: 'SomeCtrl',
  templateUrl: 'views/state.html'
})
Run Code Online (Sandbox Code Playgroud)

然后在我的视图HTML中再次定义它:

<div ng-controller="SomeCtrl"></div>
Run Code Online (Sandbox Code Playgroud)

据我所知,你应该只在一个或另一个中定义它.