0

I got confused when ever there is a call back function.

for example-

<div ng-app="myApp" ng-controller="myCtrl">
Name: <input type="text" ng-model="name"><br>
</div>

<script>
angular.module('myApp', []).controller('myCtrl', function($scope) {
    $scope.name= "John";
});
</script>

I want to know in <script> tag which function will execute first,& also want to make sure is this function return any value to some other function which is used as parameter?

maba
  • 45,597
  • 10
  • 105
  • 115
TheCurious
  • 527
  • 1
  • 4
  • 28

1 Answers1

2

If I'm not wrong, I think you are asking about Method Chaining. Read about it here

Method chaining - why is it a good practice, or not?

In your case, the module function will be executed first. The object it returns has a function called controller which will be executed second.

The callback function will be called only when Angular sees ng-controller="myctrl" directive.

Community
  • 1
  • 1
  • I am not talking about method chainning,my question is with call back function.I think ,in my question first function function($scope) will set scope for variable name then It will return any value to controller('myCtrl', retu value of function($scope)). I want to make sure how the flow is? – TheCurious Apr 08 '15 at 07:03
  • The controller function doesn't execute your callback and your function doesn't return any value to controller function. When Angular sees `ng-controller` directive, it invokes your callback with the scope as parameter. –  Apr 08 '15 at 07:09