A repeating method is executed twice for 1 call


I am new to Angularjs and Restangular noob.
Here's my problem:

On my main controller, I have this:

angular.module('examplesiteApp')
  .controller('MainCtrl', function ($scope,$location,Restangular) {

    Restangular.setBaseUrl('http://api.example.com/api/v1/');
    var baseAccounts = Restangular.all('auth/register/');
    console.log(baseAccounts);

      

in this command, I get two items (the same) that are logged into my console.

I read a similar question and it says using ng-controller

with $routeProvider

that is causing the problem.

Here is my app.js

.config(function ($routeProvider, $locationProvider,uiGmapGoogleMapApiProvider) {
    uiGmapGoogleMapApiProvider.configure({
        key: 'secret_shit_or_not',
        v: '3.17',
        libraries: 'geometry,visualization,places'
    });
    $routeProvider
      .when('/', {
        templateUrl: 'views/home/slider.html',
        controller: 'MainCtrl'
      })

      

The template looks like this:

<body ng-controller="GeneralCtrl">
    <!--[if lt IE 7]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
    <!-- Add your site or application content here -->
    <div ng-include src="'views/main.html'"></div>
    <div ng-view></div>

      

depending on url ng-view gets a certain value (dynamic process). GeneralController is a simple controller:

angular.module('peersiteApp')
  .controller('GeneralCtrl', function ($scope , $location) {
    $scope.awesomeThings = [
      'HTML5 Boilerplate',
      'AngularJS',
      'Karma'
    ];
    $scope.isAt = function(route){
      return route === $location.path();
    };
  });

      


Can you tell me why I quit twice because of the waiting list? Help Angular Snow John that I am.

+3


source to share


1 answer


Found a solution:



I was calling ng controller inside an additional view.

+2


source







All Articles