1

i have problem with loading angular. This is my code:

    var myApp = angular.module("myApp", ["ngSanitize"]);
myApp.controller("MyAppController",
    function myAppController($scope, $http, $log, $rootScope, listsModel) {
        $scope.$log = $log;
    });

<div ng-app="myApp ">
    <div ng-controller="MyAppController">
        <script>console.log("A")</script>
        {{$log.debug("B")}}
    </div>
</div>

This code write to console this: A, B, B I think that angular loading multiple. Why? What can I do? Thanks

4
  • show us your states Commented Apr 3, 2017 at 5:21
  • @bluray: Can you show your routes? Commented Apr 3, 2017 at 5:33
  • 1
    Remove the extra space in "myApp ", there is no app to load because of the space Commented Apr 3, 2017 at 5:34
  • The doubt is that, your state/route is invoking your controller from js file, plus your html is doing it again when it is loaded. Commented Apr 3, 2017 at 5:42

1 Answer 1

3

Your controller is not loaded twice it's the digest cycle that is running twice at the beginning when the application is loaded since watch is registered to every log so it will be printed twice. It will log twice only first time moreover if there is more digest cycle it will be logged again.

Sign up to request clarification or add additional context in comments.

3 Comments

Its normal? I should do something about it?
it's normal situation
@bluray It's normal because the first time it runs to check the result and the second time it runs again to check if the result is still the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.