AngularJS Simple Example

by Farzad Cyrus

HTML

<!--
<div ng-app ng-controller="LoginController">
    <div>Hello {{ user.firstName }}</div>
    <input ng-model="user.firstName">
    <input type="submit" ng-click="login()" value="Login">
    <div ng-repeat="login in logins">{{ login }}</div>
</div>
-->

<hr>


<div id="example">
	<input type="text" value="hello">
	<p>Update: <strong></strong> and the length is <span></span>
	</p>
</div>

JavaScript

/*
function LoginController($scope) {
    $scope.user = {
        firstName: "Foo",
        lastName: "Bar"
    };
    $scope.logins = [];
    $scope.login = function () {
        $scope.logins.push($scope.user.firstName + " was logged in.");
    };
}
*/


function app (){


	// model
	this.container = $('#example');
	this.input = this.container.find('input');
	this.inputValue = this.input.val();
	this.p = this.container.find('p strong');
	this.l = this.container.find('p span');
	this.length = this.inputValue.length;
	
	this.ui();
	
	
};

app.prototype.ui = function(value, length){

	var self = this;	


	$('body').keydown(function(event){

		self.inputValue = self.input.val();
		self.length = self.inputValue.length;
		//self.console.error(inputValue);
		self.p.html(self.inputValue);
		self.l.html(self.length);	

	});

		
};



$(document).ready(function(){


	

	var MyApp = new app();


	
	
});