Hamed
Hamed

Reputation: 410

Double calling controller in Angular JS?

I have controller with method that does AJAX request:

.controller('EditProfileController', ['$scope', '$http') {
   // Do AJAX query here

   // Some methods for update profile
}]);

Also I have $routeProvider in this Angular JS file:

.config(function ($routeProvider) {
    $routeProvider
        .when('/profile/personal/:type', {
            templateUrl: '/personal.html',
            controller: 'EditProfileController'
    })
}

Problem is that when I open page with URL /profile/personal/:type it calls again controller EditProfileController and calls AJAX method inside.

How I can fix it?

HTML code:

<div ng-controller="EditProfileController">
   <!-- Here are loaded data from AJAX response
</div>

Solution: Problem was in double ng-view in template:

<div ng-show="isLoaded" ng-view></div>
<div ng-show="!AILoading" ng-view></div>

Upvotes: 1

Views: 625

Answers (1)

juco
juco

Reputation: 6342

Simply remove the ng-controller directive from the HTML as the router is already taking care of this

Upvotes: 7

Related Questions