-1

I've 2 functions in the scope f1 and f2, and I call f2 in the middle of f1.I can't get why f2 is called at the end of f1.(f2 edits the view). For example, with

.....
$scope.f1 = function() {
   console.log("A");
   $scope.f2();
   console.log("C");
}

$scope.f2 = function() {
   console.log("B");
}

I get the output A C B

Why the procedural flow is not followed?In the real code, f2 manages the view.

Jonas
  • 121,568
  • 97
  • 310
  • 388

2 Answers2

1

enter image description hereThis seems to be working fine for me. See below JSFiddle: https://jsfiddle.net/sagarag05/gzvnsth0/4/

See attached screenshot below.

function TestController($scope) {

  $scope.func1 = function(){
    console.log('A');
    $scope.func2();
    console.log('C');
  }

  $scope.func2 = function() {
   console.log('B');
  }
  $scope.func1();
}
Sagar Agrawal
  • 639
  • 1
  • 7
  • 17
0

The code produces A B C as expected.

$scope = {}
$scope.f1 = function() {
   console.log("A");
   $scope.f2();
   console.log("C");
}

$scope.f2 = function() {
   console.log("B");
}
$scope.f1();  //A B C
georgeawg
  • 48,608
  • 13
  • 72
  • 95