Published on: 17 January, 2016

AngularJS MVC Design Pattern

Posted by andy | 900 views 0 likes 0 favourites 0 comments
Tumblr Digg Google Plus

So what MVC stands for? MVC stands for Model, View and Controller. The main idea behind MVC design approach is that we have clear separation in our codes between managing the model entities, presenting the data to user (view) and the application logic which is the controller. So to sum up what is MVC can be described below.


A model can be presented as a business data that is going to be used by View to be displayed on the screen .


A view can be considered as a screen interface where all the interaction and respond are taking place. Model data is presented directly into View.


A controller will be responsible to coordinate between View and Model. Any changes being made in the Model will be automatically changed or synced by controller in the View entity.

In Angular applications, the view entity is the html DOM object while the controllers are the JavaScript classes that will perform the business logic and the model entities are from object properties which can be sourced from database object.

Let see the example of how MVC works in action. We will create a list of books available for you to purchase from Amazon. The book item entity will be the Model, while the html DOM contains as UL List will be the View and then we define a BookController app in javascript which will perform the business logic displaying model in entity view.

<html ng-app='bookApp'>
<title>Example of AngularJS</title>
<body ng-controller='BookController'>
	<style type='text/css'>, li{
		} li{
		.book-title, .book-price, .book-url{
	<ul class='book-list' ng-repeat='book in books'>
			<div class='book-image'><a target='_blank' href='{{book.url}}'><img src='{{book.imageURL}}' alt='Read book {{}}'/></a></div>
			<div class='book-desc'>
				<div class='book-title'><a target='_blank' href='{{book.url}}'>{{}}</a></div>
				<div class='book-price'>{{book.price | currency}}</div>
				<div class='book-url'><a target='_blank' href='{{book.url}}'>Read more</a></div>
				<div class=''><button ng-click="getBook(book)">Click Me</button> <button ng-click="remove($index)">Remove Me</button></div>
<script src=""></script>
	var mybookModule = angular.module('bookApp', []);
		function ($scope) {
			$scope.books = [
				{name: 'Pro AngularJS',  price: 42.74, imageURL: '', url: ''},
				{name: 'Professional AngularJS',  price: 35.95, imageURL: '', url: ''},
				{name: 'Learning AngularJS',  price: 33.94, imageURL: '', url: ''}
			$scope.remove = function(index) {
				$scope.books.splice(index, 1);
			$scope.getBook = function(book){
				alert( + ' ($' + book.price + ')');

Demo of MVC AngularJS

The ng-controller tells AngularJS that the area of the <body> and </body> will be managed by BookController. While the ng-repeat will be used as a for loop to each model entity to be displayed in the DOM. Remember for data binding in AngularJS, you just need to specify double curly open and close {{ }}.

You can see the actual demo below.


There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.