AngularJS Controller example

AngularJS Controller example

In this example we will create simple AngularJS file with controller and create one variable “userName” keep in scope also bind its data to div element.

  • HTML page:
<!DOCTYPE html>
<html data-ng-app="myapp2">
<head>
<meta charset="ISO-8859-1">
<title>AngularJS Controller example</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script type="text/javascript">

	var app = angular.module('myapp2',[]);
	app.controller('myController',function($scope){
		$scope.userName = "Java Honk";	
	});

</script>
</head>
<body data-ng-controller="myController">
	<input type="text" data-ng-model="userName">
	<div>Hello, {{userName}}!</div>
</body>
</html>
  • Output:

AngularJS Controller example

 

Run this example in Plunker here

Leave a Reply

Your email address will not be published. Required fields are marked *