i am started working on angular js no i am trying to use Controller in AngularJS how to do it Please help me.
How to use Controller in AngularJS
38026-Nov-2020
Updated on 26-Nov-2020
Home / DeveloperSection / Forums / How to use Controller in AngularJS
i am started working on angular js no i am trying to use Controller in AngularJS how to do it Please help me.
Anonymous User
27-Nov-2020Hi ,
Here we will explain how to use controller in AngularJS.
AngularJS controller to control the flow of data in the application. AngularJS controller is defined with ng-controller directive. AngularJS controller is a JavaScript object containing attributes/properties and functions. AngularJS controller accepts $scope as a parameter which refers to the application/module that controller is to control.
Now I am going to declared a controller MyController using ng-controller directive. See Below –
MyController
Above Code MyController defined as a JavaScript object with $scope as argument. $scope refers to application which is to use the MyController object. $scope.User is property of MyController object. Name and Age are two properties of $scope.User object. We've defined the default values Name=”Aditya Kumar Patel” and Age=”24”
Now I am going to use controller in our HTML page . show below-
Simple Example
Now we run application and see Output