Steve Gaines Steve Gaines - 1 year ago 62
AngularJS Question

Why does AngularJS send double network requests?

I have the code shown below in a controller for an AngularJS Single Page Application. When this page runs and I check Developer Tools Network (in IE, Chrome, and Firefox) it always shows 2 successful GET calls to Tables, and two empty OPTIONS calls to Tables. Why are there 2 GET calls? Is that normal or did I do something wrong in my code? Also, why does it issue the 2 OPTIONS calls?

"use strict";

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

var url = $scope.$parent.BaseUrl + "Tables";
.then(function mySuccess(response)
$scope.MyTables =;

Answer Source

This has happened to me in the past, the issue was that I had defined my controller twice, once in the route:

.state('app.state', {
  url: '/state',
  controller: 'SomeCtrl',
  templateUrl: 'views/state.html'

and then defined it again in my view HTML:

<div ng-controller="SomeCtrl"></div>

As far as I am aware, you should only define it in one or the other.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download