SlideShare a Scribd company logo
@nishanil
Building MVVM &
Single Page Apps (SPA)
in JavaScript
Nishanth Anil
Technical Evangelist | Infragistics
na@nnish.com | nnish.com
@nishanil
Web Development
Have you considered Mobile Users?
@nishanil
AFTER iPhone
@nishanil
@nishanil
User Experience!
• Mobile Specific Web? m.yourwebsite.com
• Native App instead?
• Hybrid?
• Responsive Web?
@nishanil
Your Tools!
@nishanil
JavaScript
then, now, & forever!
@nishanil
JavaScript MV* F/Ws
@nishanil
Intro to MVVM
@nishanil
The MVVM Pattern
• Model-View View-Model
• Software architectural design pattern
• Emerged in the 2005 timeframe to support the declarative data binding features of
WPF / XAML
@nishanil
Benefits
• Developer/Designer Collaboration without Conflict - Since the UI is void of any
non-visual code such as business logic, the team’s designer can confidently work
on modifying the code without worrying about breaking the programmer’s code.
• Testable Code - Decoupling the view from the view model enables us to write
clean unit tests.
• Code Maintainability - Testable, decoupled code is easier to maintain. A bug can
be found much more easily if there is only one place to inspect.
@nishanil
Demo
@nishanil
MVVM in
JavaScript
@nishanil
Introducing KnockoutJS
• Knockout is an open source JavaScript library that enables MVVM applications by
implementing binding
• Properties in the Model classes are of type ko.observable
• Observables in JavaScript notify subscribers of property changes
• Supports all major browsers
6+ 2+
@nishanil
Comparing JavaScript to WPF
Runtime
CLR - XAML Binding
Business Logic
C#
Presentation
XAML
Window
Runtime
Browser - Knockout
Business Logic
JS
Presentation
HTML
Page
@nishanil
Step 1: Reference KO in the View
<script type="text/javascript" src="../scripts/ko/knockout-
2.1.0.js"></script>
@nishanil
Step 2: Associate the View Model with the View
<script>
$(document).ready(function () {
// Instantiate the CustomerViewModel model and apply bindings
var customerViewModel = new CustomerViewModel();
ko.applyBindings(customerViewModel);});
</script>
@nishanil
Step 3: Define Declarative Bindings in the View
<div id="ListMenu" >
<ul data-bind="foreach: customers">
<div>
<img width='100' height='100' align='middle' style='padding:5px'
data-bind="attr: { src: pictureURL }"></img>
<a style='font-size:15pt;cursor:pointer;color:#067EBF'
data-bind="text: fullName "></a>
</div>
</ul>
</div>
@nishanil
Understanding Bindings
• Bindings are declared in the visual element mark-up by using the data-bind
attribute.
• These bindings are associated with view model properties that are known as
observables.
• Observables are properties that will automatically issue notifications whenever
their value changes.
function CustomerViewModel() {
var self = this;
// Properties
self.customers = ko.observableArray();
@nishanil
Knockout Bindings
• foreach: Lets you iterate through a loop and apply the same markup to each item
in the list. This is used to render the to-do lists and to-do items. Within the
foreach, the bindings are applied to the elements of the list.
• visible: Used to toggle visibility. Hide markup when a collection is empty, or make
the error message visible.
• value: Used to populate form values.
• click: Binds a click event to a function on the view model.
@nishanil
Demo
@nishanil
Single Page
Application
@nishanil
What is a SPA?
“Single-page application” (SPA) is the
general term for a web application that
loads a single HTML page and then
updates the page dynamically, instead
of loading new pages. After the initial
page load, the SPA talks with the
server through AJAX requests.
@nishanil
VIEW
@nishanil
SPA with Knockout
@nishanil
SPA Demo
@nishanil
Resources
• Single Page Apps with MVC & ASP.NET - http://www.asp.net/single-page-
application/overview/introduction/knockoutjs-template
• Knockout & MVVM Step by Step - http://www.developer-
tech.com/news/2012/dec/13/knockoutjs-mvvm-framework-jquery-developers/
@nishanil
Thank You!
Nishanth Anil
nnish.com

More Related Content

PPTX
Building databound JavaScript apps with Knockoutjs
PPTX
Knockout
PPTX
Angular js Classes in Pune
PDF
Itroducing Angular JS
PPTX
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
PDF
APAC Webinar: Say Hello To Xamarin.Forms
PPTX
Apple Watch Intro
PPTX
School Management System ppt
Building databound JavaScript apps with Knockoutjs
Knockout
Angular js Classes in Pune
Itroducing Angular JS
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
APAC Webinar: Say Hello To Xamarin.Forms
Apple Watch Intro
School Management System ppt

Similar to Building mvvm & single pageapps in js (20)

PPTX
Training: MVVM Pattern
PPTX
Fundaments of Knockout js
PPT
Porting the Legacy Application to Composite Application Guidance
PPT
MVC(Model View Controller),Web,Enterprise,Mobile
PPTX
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
PDF
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
PPTX
Angular js
PPTX
Adopting MVVM
PPTX
Design Pattern - MVC, MVP and MVVM
PPTX
Introduction to single page application with angular js
PDF
Modern webtechnologies
ODP
Introduction to Knockout Js
PDF
PDF
Unlock the Power of Mui Breakpoints and Make Great Projects.pdf
PDF
Leveling up with AngularJS
PPTX
Kalp Corporate Angular Js Tutorials
PDF
AngularJS 101 - Everything you need to know to get started
PPTX
Intoduction to Angularjs
PDF
Models used in iOS programming, with a focus on MVVM
KEY
AngularJS for designers and developers
Training: MVVM Pattern
Fundaments of Knockout js
Porting the Legacy Application to Composite Application Guidance
MVC(Model View Controller),Web,Enterprise,Mobile
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Angular js
Adopting MVVM
Design Pattern - MVC, MVP and MVVM
Introduction to single page application with angular js
Modern webtechnologies
Introduction to Knockout Js
Unlock the Power of Mui Breakpoints and Make Great Projects.pdf
Leveling up with AngularJS
Kalp Corporate Angular Js Tutorials
AngularJS 101 - Everything you need to know to get started
Intoduction to Angularjs
Models used in iOS programming, with a focus on MVVM
AngularJS for designers and developers
Ad

More from Nish Anil (7)

PPTX
[MobConf] Go mobile with C#, Visual Studio & Xamarin
PDF
[MobConf] Programming wearables in c#
PDF
[Bdotnet] Cloud connected mobile apps
PPTX
Evolve recap XHackers, Bangalore
PDF
iOS & Android Dev in C# & Visual Studio using Xamarin
PPTX
Using mvvm on the web using knockoutjs & ignite ui
PDF
Infragistics: Getting Started with MVVM in WPF & Silverlight
[MobConf] Go mobile with C#, Visual Studio & Xamarin
[MobConf] Programming wearables in c#
[Bdotnet] Cloud connected mobile apps
Evolve recap XHackers, Bangalore
iOS & Android Dev in C# & Visual Studio using Xamarin
Using mvvm on the web using knockoutjs & ignite ui
Infragistics: Getting Started with MVVM in WPF & Silverlight
Ad

Recently uploaded (20)

PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
A Presentation on Touch Screen Technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
A Presentation on Artificial Intelligence
PDF
Approach and Philosophy of On baking technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Hybrid model detection and classification of lung cancer
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
project resource management chapter-09.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Encapsulation theory and applications.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Mushroom cultivation and it's methods.pdf
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
A comparative study of natural language inference in Swahili using monolingua...
A Presentation on Touch Screen Technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
NewMind AI Weekly Chronicles - August'25-Week II
A Presentation on Artificial Intelligence
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Hybrid model detection and classification of lung cancer
Digital-Transformation-Roadmap-for-Companies.pptx
project resource management chapter-09.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
1. Introduction to Computer Programming.pptx
Chapter 5: Probability Theory and Statistics
DP Operators-handbook-extract for the Mautical Institute
Encapsulation theory and applications.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Mushroom cultivation and it's methods.pdf
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf

Building mvvm & single pageapps in js