{"id":3124,"date":"2015-04-07T16:15:41","date_gmt":"2015-04-07T13:15:41","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=3124"},"modified":"2017-12-19T16:54:03","modified_gmt":"2017-12-19T14:54:03","slug":"angular-js-controller-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/","title":{"rendered":"Angular.js Controller Example"},"content":{"rendered":"<p>Hello! In today&#8217;s example we &#8216;ll see how do Angular&#8217;s <code><a href=\"https:\/\/docs.angularjs.org\/guide\/controller\" target=\"_blank\">controllers<\/a><\/code> work.<\/p>\n<p>To get into this, I chose a simple form concept, where the user is prompt to insert his username. This updates an informative message (i.e. &#8220;Your username is &#8220;); I&#8217;ll also include a reset button, for demonstration purposes.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;LXJcMJZXSsqGXYW8&#8242;]<\/p>\n<h2>1. Required Background<\/h2>\n<p>Before getting into the technical part of this example, let me introduce you the <code><a href=\"https:\/\/docs.angularjs.org\/guide\/scope\" target=\"_blank\">$scope<\/a><\/code> element.<\/p>\n<h3>1.1 What are scopes?<\/h3>\n<p>AngularJS supports the <a href=\"http:\/\/www.tutorialspoint.com\/design_pattern\/mvc_pattern.htm\" target=\"_blank\">MVC pattern<\/a>, with the <code>$scope<\/code> object associated with the application model. In fact, it&#8217;s the glue between View and Controller. In addition, they hold the Model data that we need to pass to View and use Angular&#8217;s two way data binding to bind model data to View.<\/p>\n<p>Their responsibility is to initialize the data that the View needs to display. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application.<\/p>\n<h3>1.2 What are controllers?<\/h3>\n<p>Generally, an Angular controller is a JavaScript constructor function that augments the <code>$scope<\/code> object. It can be attached to the DOM through the <code>ng-controller<\/code> directive, where Angular instantiates a new Controller object, using the specified controller&#8217;s constructor function. Using a controller, we can instantiate a new child scope as an injectable parameter to controller&#8217;s function. The injected parameter is accessible through <code>$scope<\/code>.<\/p>\n<h4>1.2.1 How to initialize the state of a <code>$scope<\/code> object<\/h4>\n<p>When creating an application, we need to set up the initial state for the Angular <code>$scope<\/code>. This can be feasible by attaching properties to the <code>$scope<\/code> object. These properties contain the View (the Model, which will be presented by the View). All the <code>$scope<\/code> properties will be available to the <a href=\"https:\/\/docs.angularjs.org\/guide\/templates\" target=\"_blank\">template<\/a> at the point in the DOM, where the controller is registered.<\/p>\n<h4>1.2.2 A small example<\/h4>\n<p>We here create a HelloController, which attaches a <code>helloMessage<\/code> property containing the string &#8220;Hello World!&#8221; to the <code>$scope<\/code>:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar myApp = angular.module('myApp',&#x5B;]);\r\n\r\nmyApp.controller('HelloController', &#x5B;'$scope', function($scope) {\r\n  $scope.helloMessage= 'Hello World!';\r\n}]);\r\n<\/pre>\n<p>What is actually done, is an Angular <a href=\"https:\/\/docs.angularjs.org\/guide\/module\" target=\"_blank\">module<\/a> creation ( <code>myApp<\/code> ) for our app. We then add the controller&#8217;s constructor function to the module, using the <code>.controller()<\/code> method. This keeps the controller&#8217;s constructor function out of the global scope.<\/p>\n<p>Next, we attach our controller to the DOM using the <code>ng-controller<\/code> directive. The <code>helloMessage<\/code> property can now be data-bound to the template:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;div ng-controller=&quot;HelloController&quot;&gt;\r\n  {{ helloMessage }}\r\n&lt;\/div&gt;\r\n<\/pre>\n<h4>1.2.3 Controllers&#8217; use case<\/h4>\n<p>Generally, we usually use controllers either to setup the initial state of the <code>$scope<\/code> object or to add behavior to the <code>$scope<\/code> object.<\/p>\n<p>Cases that we cannot use controllers are to:<\/p>\n<ul>\n<li>Manipulate DOM (controllers should contain only business logic).<\/li>\n<li>Format input; use angular <a href=\"https:\/\/docs.angularjs.org\/guide\/forms\" target=\"_blank\">form controls<\/a> instead.<\/li>\n<li>Filter output; use angular <a href=\"https:\/\/docs.angularjs.org\/guide\/filter\" target=\"_blank\">filters<\/a> instead.<\/li>\n<li>Share code or state across controllers; use angular <a href=\"https:\/\/docs.angularjs.org\/guide\/services\" target=\"_blank\">services<\/a> instead.<\/li>\n<li>Manage the lifecycle of other components (i.e. to create service instances).<\/li>\n<\/ul>\n<h2>2. Our Example<\/h2>\n<p>As I fore-mentioned, a username text field, with a reset button and an updateable message, related to the controller&#8217;s logic.<\/p>\n<p><u><code>index.html<\/code><\/u><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=&quot;en&quot;&gt;\r\n&lt;head&gt;\r\n  &lt;meta charset=&quot;UTF-8&quot;&gt;\r\n  &lt;title&gt;AngularJS Controller Example&lt;\/title&gt;\r\n  \r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/2.3.2\/css\/bootstrap.min.css&quot;&gt;\r\n  &lt;script src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.2.26\/angular.min.js&quot;&gt;&lt;\/script&gt;\r\n  &lt;script src=&quot;script.js&quot;&gt;&lt;\/script&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; &gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body ng-app=&quot;myApp&quot;&gt;\r\n\t&lt;h2&gt;AngularJS Controller Example&lt;\/h2&gt;\r\n\t&lt;div ng-controller=&quot;UserController&quot;&gt;\r\n\t\t&lt;form&gt;\r\n\t\t&lt;label&gt;Name:&lt;\/label&gt;\r\n\t\t&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;username&quot; ng-model=&quot;username&quot;&gt;\r\n\t\t&lt;button class=&quot;btn btn-link&quot; ng-click=&quot;reset()&quot;&gt;Reset&lt;\/button&gt;\r\n\r\n\t\t&lt;p&gt;Your username is {{username}}&lt;\/p&gt;\r\n\t\t&lt;\/form&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>As line 9 clarifies, our controller&#8217;s functionality will be defined into the <code>script.js<\/code> file. In line 13, we declare our Angular application in the name of <code>myApp<\/code>. Lines 15-23 contain the important <code>div<\/code> which interacts with <code>UserController<\/code> (this, in conjunction with line&#8217;s 9 included script, means that our controller&#8217;s logic is contained int the javascript file.<\/p>\n<p>What else is important here, from Angular&#8217;s perspective, is the <code>ng-model<\/code> attribute of the text field, in line 18. This is actually a directive that binds our text field to the username property on the scope, with the help of UserController, which is created and exposed by this directive.<\/p>\n<p>That is, the text field&#8217;s value can be changed inside the controller, by accessing the username property from the scope object (i.e. <code>$scope.username<\/code>).<\/p>\n<p>What about line 19 and <code>ng-click<\/code>? Well, using the <code>ng-controller<\/code> directive, we bind the <code>div<\/code> element including its children to the context of <code>UserController<\/code> controller. The <code>ng-click<\/code> directive will call the <code>reset()<\/code> function of our controller, when the reset button is clicked.<\/p>\n<p>In line 21, there is the message that we earlier discussed, where, in general, the double curly braces notation ( <code>{{ }}<\/code> ) binds expressions to elements.<\/p>\n<p>Enough said for our View&#8217;s implementation. Let&#8217;s now code the Controller and then explain the necessary details.<\/p>\n<p><u><code>script.js<\/code><\/u><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar myApp = angular.module('myApp', &#x5B;]);\r\n\r\nmyApp.controller('UserController', &#x5B;'$scope', function($scope) {\r\n\t$scope.username = 'unknown';\r\n\t\r\n\t$scope.reset = function() {\r\n        $scope.username = '';\r\n    };\r\n}]);\r\n<\/pre>\n<p>At first, we have to define that this script is about an Angular module; especially the one defined in our <code>index.html<\/code>, the one named as <code>myApp<\/code> application. We then define the controller&#8217;s name and initialize the <code>username<\/code> with the value of &#8216;unknown&#8217;. That is, when the application is loaded to the browser, the text field will contain a predefined value, but on user change, <code>ng-model<\/code> interferes with the controller and updates the username&#8217;s value (the curly braces variable binded in the View).<\/p>\n<p>Obviously, the reset function is used to empty the text fiel&#8217;s content.<\/p>\n<h2>3. Demo<\/h2>\n<p>Let&#8217;s now display a quick demo. This is the initial view:<\/p>\n<figure id=\"attachment_3162\" aria-describedby=\"caption-attachment-3162\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/first1.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/first1.png\" alt=\"Figure 1. Initial state of the app\" width=\"500\" height=\"218\" class=\"size-full wp-image-3162\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/first1.png 500w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/first1-300x131.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3162\" class=\"wp-caption-text\">Figure 1. Initial state of the app<\/figcaption><\/figure>\n<p>If we hit the reset button, our text field gets empty:<\/p>\n<figure id=\"attachment_3163\" aria-describedby=\"caption-attachment-3163\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/reset.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/reset.png\" alt=\"Figure 2. The reset button\" width=\"500\" height=\"211\" class=\"size-full wp-image-3163\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/reset.png 500w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/reset-300x127.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-3163\" class=\"wp-caption-text\">Figure 2. The reset button<\/figcaption><\/figure>\n<p>Finally, here is the updated message, which, in conjuction with the user input, result to a dynamic view in our application:<\/p>\n<figure id=\"attachment_3164\" aria-describedby=\"caption-attachment-3164\" style=\"width: 495px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/user_input.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/user_input.png\" alt=\"Figure 3. User input\" width=\"495\" height=\"212\" class=\"size-full wp-image-3164\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/user_input.png 495w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/user_input-300x128.png 300w\" sizes=\"(max-width: 495px) 100vw, 495px\" \/><\/a><figcaption id=\"caption-attachment-3164\" class=\"wp-caption-text\">Figure 3. User input<\/figcaption><\/figure>\n<h2>4. Download the project<\/h2>\n<p>This was an example of an AngularJS Controller.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here : <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/03\/angularjs_controller.zip\"><strong>angularjs_controller.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In today&#8217;s example we &#8216;ll see how do Angular&#8217;s controllers work. To get into this, I chose a simple form concept, where the user is prompt to insert his username. This updates an informative message (i.e. &#8220;Your username is &#8220;); I&#8217;ll also include a reset button, for demonstration purposes. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &hellip;<\/p>\n","protected":false},"author":63,"featured_media":909,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-3124","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Angular.js Controller Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Hello! In today&#039;s example we &#039;ll see how do Angular&#039;s controllers work. To get into this, I chose a simple form concept, where the user is prompt to\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Angular.js Controller Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Hello! In today&#039;s example we &#039;ll see how do Angular&#039;s controllers work. To get into this, I chose a simple form concept, where the user is prompt to\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/toubou.techblog\/\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-07T13:15:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T14:54:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Thodoris Bais\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ThodorisBais\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thodoris Bais\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/\"},\"author\":{\"name\":\"Thodoris Bais\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d\"},\"headline\":\"Angular.js Controller Example\",\"datePublished\":\"2015-04-07T13:15:41+00:00\",\"dateModified\":\"2017-12-19T14:54:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/\"},\"wordCount\":1105,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"articleSection\":[\"Angular.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/\",\"name\":\"Angular.js Controller Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"datePublished\":\"2015-04-07T13:15:41+00:00\",\"dateModified\":\"2017-12-19T14:54:03+00:00\",\"description\":\"Hello! In today's example we 'll see how do Angular's controllers work. To get into this, I chose a simple form concept, where the user is prompt to\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Angular.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/angular-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Angular.js Controller Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d\",\"name\":\"Thodoris Bais\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g\",\"caption\":\"Thodoris Bais\"},\"description\":\"Thodoris is an Oracle Certified Associate Java Programmer and currently works as a Junior Software Developer, for Intrasoft International S.A. He holds a diploma at Informatics &amp; Telecommunications Engineering and is interested in continuous development.\",\"sameAs\":[\"http:\/\/thodorisbais.blogspot.com\",\"https:\/\/www.facebook.com\/toubou.techblog\/\",\"https:\/\/instagram.com\/thodoris.bais\/\",\"https:\/\/www.linkedin.com\/pub\/thodoris-bais\/69\/6b7\/408\",\"https:\/\/x.com\/@ThodorisBais\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/thodoris-bais\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Angular.js Controller Example - Web Code Geeks - 2026","description":"Hello! In today's example we 'll see how do Angular's controllers work. To get into this, I chose a simple form concept, where the user is prompt to","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/","og_locale":"en_US","og_type":"article","og_title":"Angular.js Controller Example - Web Code Geeks - 2026","og_description":"Hello! In today's example we 'll see how do Angular's controllers work. To get into this, I chose a simple form concept, where the user is prompt to","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/toubou.techblog\/","article_published_time":"2015-04-07T13:15:41+00:00","article_modified_time":"2017-12-19T14:54:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","type":"image\/jpeg"}],"author":"Thodoris Bais","twitter_card":"summary_large_image","twitter_creator":"@ThodorisBais","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Thodoris Bais","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/"},"author":{"name":"Thodoris Bais","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d"},"headline":"Angular.js Controller Example","datePublished":"2015-04-07T13:15:41+00:00","dateModified":"2017-12-19T14:54:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/"},"wordCount":1105,"commentCount":3,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","articleSection":["Angular.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/","name":"Angular.js Controller Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","datePublished":"2015-04-07T13:15:41+00:00","dateModified":"2017-12-19T14:54:03+00:00","description":"Hello! In today's example we 'll see how do Angular's controllers work. To get into this, I chose a simple form concept, where the user is prompt to","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/angularjs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/angular-js\/angular-js-controller-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Angular.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/angular-js\/"},{"@type":"ListItem","position":4,"name":"Angular.js Controller Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/f622d6017801d9aa8131e1ae69bbdd0d","name":"Thodoris Bais","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc31ee119255c1e4aa4a4f34858284d907cce53d033584d86b0e3de46db7d0ff?s=96&d=mm&r=g","caption":"Thodoris Bais"},"description":"Thodoris is an Oracle Certified Associate Java Programmer and currently works as a Junior Software Developer, for Intrasoft International S.A. He holds a diploma at Informatics &amp; Telecommunications Engineering and is interested in continuous development.","sameAs":["http:\/\/thodorisbais.blogspot.com","https:\/\/www.facebook.com\/toubou.techblog\/","https:\/\/instagram.com\/thodoris.bais\/","https:\/\/www.linkedin.com\/pub\/thodoris-bais\/69\/6b7\/408","https:\/\/x.com\/@ThodorisBais"],"url":"https:\/\/www.webcodegeeks.com\/author\/thodoris-bais\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/3124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=3124"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/3124\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/909"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=3124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=3124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=3124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}