0
<html>
      <body>
           <div ng-controller="TestController">
                 Framework is {{name}}
           </div>
      </body>
</html>

Am making the above piece of html code into angular manually in the script.

var app = angular.module('TestModule',[]);
angular.bootstrap(document, app);

I want to know the difference, advantages, disadvantages in initializing the controller in the below two ways.

Model 1:

var app = angular.module('TestModule',[]);
app.controller('TestController',function($scope){
     $scope.name="Angualar";
});
angular.bootstrap(document, app);

Model2:

var app = angular.module('TestModule',[]);
window['TestController'] = function($scope){
      $scope.name="Angualar";
};
angular.bootstrap(document, app);   

Both the above models works same. When does the controller actually creates. when the scope gets creates for the controller. Kindly share your comments.

1 Answer 1

0

Model2 is the bad way to do it. Use Model1, its better and angular's way to create controllers.

In Model2 you are polluting global window scope.

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

Comments

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.