SlideShare a Scribd company logo
Technical Deep Dive into AngularJS and the
WordPress REST API
March 16th, 2016
#wprestapi
Vote for your favorite plugins:
www.pluginmadness.com
Ask Questions as We Go!
Please use the “Questions”
pane throughout the webinar
#wprestapi
Slides and recording will be made available shortly after
the webinar
What We’ll Discuss
Building on last webinar:
The WP REST API as a Springboard for Website Greatness
❖ How to make custom admin interfaces using REST API
and AngularJS
❖ Angular basics with the WordPress REST API
❖ Build a plugin admin screen (Ingot A/B testing)
#wprestapi
Quick Intros!
#wprestapi
Josh Pollock
Owner/Developer,
CalderaWP and Ingot
@josh412
❖ CalderaWP.com
❖ IngotHQ.com
❖ JoshPress.net
Anthony Burchell
Operations Engineer,
WP Engine
@antpb
❖ Started on WordPress 2.8
❖ Casual Core Contributor
❖ Antpb.com
❖ Synth nerd
Is this the new way?
What is the benefit?
● Respects standards &
separation of concerns
● Relatively easy to
learn
● Testable
● Someone else pays to
maintain it.
#thanksgoogle
But admin-ajax!
Custom or Default Routes
#wprestapi
Use Default Routes
❖ Install the plugin
❖ https://wordpress.org/plugins/r
est-api/
Make Your Own Endpoints
❖ Make your own API with
WordPress 4.4+
❖ Talk: video, slides & links
❖ Torque Article
Part One
MVC
MVCMVC
●Model
●View
●Controller
MVCModel
The model is the current set of
data, defined by the controller,
displayed by the view.
MVC$scope
Current state of the
model. Defined in
controller - used in
view.
MVCView
● The visual representation of
the data.
● In Angular this is an HTML
file.
MVCController
● Keeps the models up-to-
date using the remote API.
● Updates the model based on
your interactions with the
view.
Part Two
Bindings
MVCBindings
● Connects views to
controllers.
● HTML5 Attributes
● Template Tags: Curly
Brackets
<div ng-controller="postExample">
<form>
<input type="text" ng-model="post.title" />
</form>
<div>{{post.title}}</div>
</div>
Controller
MVCBindings
● Use controller function to
create controller...
● $scope is available in view
Template
(function(angular) {
'use strict';
angular.module('learnAngular', [])
.controller('postExample', ['$scope',
function($scope) {
$scope.post = {
title: 'Enter Title'
};
}]);
})(window.angular);
MVCBindings
● Bindings can be used to call
functions
● Examples:
○ ng-submit
○ ng-hide
Views
<div ng-controller="postExample">
<form ng-submit="submit()">
<input type="text" ng-model="post.title" />
<input type="submit" value="Save" ng-
hide="post.title == 'Enter Title'" />
</form>
<div>{{post.title}}</div>
</div>
MVCBindings
● Define functions for view on
$scope.
● Example: $scope.submit
Controller
(function(angular) {
'use strict';
angular.module('learnAngular', [])
.controller('postExample', ['$scope',
function($scope) {
$scope.post = {
title: 'Enter Title'
};
$scope.submit = function(){
alert( 'saving' );
}
}]);
})(window.angular);
MVCBindings
● ng-repeat:
○ Repeat items (like a list
of posts)
Views
<div ng-controller="postsExample">
<h3>Posts:</h3>
<div ng-repeat="post in posts">
{{post.title}}
</div>
</div>
MVCBindings
● Look mom, two controllers!
● Iterating over posts array.
(function(angular) {
'use strict';
angular.module('learnAngular', [])
.controller('postExample', ['$scope', function($scope) {
$scope.post = {
title: 'Enter Title'
};
$scope.submit = function(){
alert( 'saving' );
}
}]).controller('postsExample', ['$scope', function($scope) {
$scope.posts = [
{ title: 'Post One' },
{ title: 'Post Two' }
];
}]);
})(window.angular);
Making your own
Super Fast Super Fancy Admin Interface!
Or….
SFSFAI!
This is going to catch on...
Making your own
Super Fast Super Fancy Admin Interface!
MVCAngular
UI Router
● What URL uses what
controller and template?
● http://jpwp.me/ingot-router
ingotApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
//click tests
.state('clickTests', {
url: "/click-tests",
templateUrl: INGOT_ADMIN.partials + "/click-groups.html"
})
.state('clickTests.list', {
url: "/click-tests/all",
templateUrl: INGOT_ADMIN.partials + "/list.html",
controller: 'clickGroups'
} )
.state('clickTests.edit', {
url: "/click-tests/edit/:groupID",
templateUrl: INGOT_ADMIN.partials + "/click-group.html",
controller: 'clickGroup'
} )
.state('clickTests.new', {
url: "/click-tests/new",
templateUrl: INGOT_ADMIN.partials + "/click-group.html",
controller: 'clickGroup'
} )
});
MVCStart it up
● Include dependencies
● Adding translations to
$rootScope
var ingotApp = angular.module('ingotApp', [
'ui.router',
'ui.bootstrap',
'colorpicker.module',
'ngAria',
'ngResource',
'ngclipboard',
'ngSanitize'
] )
.run( function( $rootScope, $state ) {
$rootScope.translate = INGOT_TRANSLATION;
$rootScope.partials_url = INGOT_ADMIN.partials;
}
);
MVCAngular
$http
● Similar to jQuery AJAX
● Use to update $scope and
$state
ingotApp.controller( 'clickDelete', ['$scope', '$http',
'$stateParams', '$state', function( $scope, $http, $stateParams,
$state ){
$http({
url: INGOT_ADMIN.api + 'groups/' + $stateParams.groupID +
'?_wpnonce=' + INGOT_ADMIN.nonce,
method:'DELETE',
headers: {
'X-WP-Nonce': INGOT_ADMIN.nonce
}
} ).then(
function successCallback() {
swal( INGOT_TRANSLATION.deleted, "", "success" );
$scope.group = {};
$state.go('clickTests.list' );
}, function errorCallback( response ) {
var data = response.data;
var text = INGOT_TRANSLATION.sorry;
if( _.isObject( data ) && _.isDefined( data.message
) ){
text = data.message;
}
$state.go('clickTests.list' );
}
);
}]);
MVCFactories
● Reusable code for HTTP
● Makes data an injected
dependency -- easily
mocked/ modified
● http://jpwp.me/ingot-factory
ingotApp.factory( 'groupsFactory', function( $resource ) {
return $resource( INGOT_ADMIN.api + 'groups/:id', {
id: '@id',
_wpnonce: INGOT_ADMIN.nonce,
context: 'admin'
},{
'query' : {
transformResponse:
function( data, headers ) {
var
response = {
data: data,
headers: headers()
};
return
response;
}
},
'update':{
method:'PUT',
headers: {
'X-WP-Nonce': INGOT_ADMIN.nonce
}
},
MVCFactories
● Think of it as your own API
client
● http://jpwp.me/ingot-factory-
in-use
ingotApp.controller( 'clickGroups', ['$scope', '$http',
'groupsFactory', '$sce', function( $scope, $http, groupsFactory,
$sce ) {
var page_limit = 10;
$scope.description = $sce.trustAsHtml(
INGOT_TRANSLATION.descriptions.click );
groupsFactory.query( {
page: 1,
limit: page_limit,
context: 'admin',
type: 'click'
}, function ( res ) {
if ( res.data.indexOf( 'No matching' ) > -1 ) {
$scope.groups = {};
return;
};
$scope.groups = JSON.parse( res.data );
var total_groups = parseInt( res.headers[ 'x-ingot-total'
] );
var total_pages = total_groups / page_limit;
$scope.total_pages = new Array( Math.round( total_pages )
);
$scope.groups.shortcode = [];
} );
}]);
Resources
❖eBook: The Ultimate Guide to the WordPress REST API
http://wpeng.in/rest-api-ebook/
❖Article: Basics of AngularJS with the WordPress REST API
http://torquemag.io/2016/02/basics-of-angularjs-with-the-wordpress-rest-
api/
❖Building Apps with the WordPress REST API
https://learn.joshpress.net/downloads/building-apps-wordpress-rest-api/
❖Creating a Javascript Single Page App in the WordPress Dashboard
http://torquemag.io/2015/12/creating-javascript-single-page-app-wordpress-
dashboard/
#wprestapi
CalderaWP
REST API Course
CalderaWP.com
Q&A
Feel free to ask away in
the “Questions” pane!
Are you an agency or freelancer?
● Finish more sites in less time
● Unlimited staging installs for WordPress projects for as little
as $29 per month.
Ask about qualifying for a listing in our online consultants’ directory!
Call +1-512-827-3500, or
Chat with us wpengine.com
Myths, Mistakes & Management of WooCommerce at Scale
Wednesday, April 13th, 12 pm EDT/ 11 am CDT/ 9 am PDT/ 5 pm GMT+1
Register Now! http://wpeng.in/woo/
❖ Myths associated with scaling WooCommerce
❖ Mistakes and how to avoid them
❖ How to pick development and hosting partners
Next
Next Webinar

More Related Content

PPTX
Webinar: On-Page SEO Tips and Tricks
PPTX
Pitch Perfect: Agency Secrets to Winning More Business
PPTX
Optimizing Your Site for Holiday Traffic
PPTX
Webinar: Myths, Mistakes and Management of WooCommerce at Scale
PPTX
Webinar: You Are Too Cheap!
PDF
Building and future-proofing your WordPress sites with the Genesis Framework
PDF
Don't lose revenue. Go viral with no downtime.
PDF
The Fast Track to Mastering Modern WordPress - Rob Stinson & Carrie Dils
Webinar: On-Page SEO Tips and Tricks
Pitch Perfect: Agency Secrets to Winning More Business
Optimizing Your Site for Holiday Traffic
Webinar: Myths, Mistakes and Management of WooCommerce at Scale
Webinar: You Are Too Cheap!
Building and future-proofing your WordPress sites with the Genesis Framework
Don't lose revenue. Go viral with no downtime.
The Fast Track to Mastering Modern WordPress - Rob Stinson & Carrie Dils

What's hot (20)

PDF
Security Webinar: Harden the Heart of Your WordPress SiteSe
PPTX
WordPress Management & Marketing Tools
PPTX
How WPMaintain Improved Page Speed by 16%
PPTX
Wp snapper review
PPTX
SEO Myths & WP Magic - WordCamp Boston 2011
PDF
Technical SEO for WordPress
PPTX
Increasing Traffic Through Optimization : The Importance of Site Speed
PPTX
WP-CLI: WordCamp NYC 2015
PPTX
Top 10 WordPress Plugins
PPTX
PDF
WordCamp Bournemouth 2014 - Designing with data in WordPress
PDF
Using Page Builders For Fun And Profit
PDF
Rapid WordPress theme development
PDF
10 things Not To Do With WordPress
PDF
WordCamp Mumbai 2017: How to get more involved with WordPress
PPT
Introduction To JavaScript
PDF
10 Things Not To Do With WordPress
PPTX
WordPress SEO Site Optimization Strategies & Techniques
PDF
WordPress with WP Engine and the Agency Partner Program: Getting Set Up
DOC
Analysis report didm
Security Webinar: Harden the Heart of Your WordPress SiteSe
WordPress Management & Marketing Tools
How WPMaintain Improved Page Speed by 16%
Wp snapper review
SEO Myths & WP Magic - WordCamp Boston 2011
Technical SEO for WordPress
Increasing Traffic Through Optimization : The Importance of Site Speed
WP-CLI: WordCamp NYC 2015
Top 10 WordPress Plugins
WordCamp Bournemouth 2014 - Designing with data in WordPress
Using Page Builders For Fun And Profit
Rapid WordPress theme development
10 things Not To Do With WordPress
WordCamp Mumbai 2017: How to get more involved with WordPress
Introduction To JavaScript
10 Things Not To Do With WordPress
WordPress SEO Site Optimization Strategies & Techniques
WordPress with WP Engine and the Agency Partner Program: Getting Set Up
Analysis report didm
Ad

Viewers also liked (16)

PDF
Laravel Restful API and AngularJS
PDF
WordPress: React Way
PPTX
WP Engine #WooConf 2016: Top Live Tweet Quotes
PPTX
The WordPress REST API as a Springboard for Website Greatness
PPTX
Personalization With WordPress - Interactive Strategies 2016
PPTX
8 Hidden Features on WordPress
PDF
Building a JavaScript App powered by WordPress & AngularJS
PPTX
Today's Security Threat Landscape
PDF
Introduction to plugin development
PDF
Introduction to AngularJS For WordPress Developers
PDF
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
PDF
Your Workflow, Your Way with WP Engine
PPTX
The Future of Analytics: Multichannel Attribution
PDF
Webinar: Experts Weigh in on the State of WordPress for 2017
PPTX
Webinar: AngularJS and the WordPress REST API
Laravel Restful API and AngularJS
WordPress: React Way
WP Engine #WooConf 2016: Top Live Tweet Quotes
The WordPress REST API as a Springboard for Website Greatness
Personalization With WordPress - Interactive Strategies 2016
8 Hidden Features on WordPress
Building a JavaScript App powered by WordPress & AngularJS
Today's Security Threat Landscape
Introduction to plugin development
Introduction to AngularJS For WordPress Developers
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Your Workflow, Your Way with WP Engine
The Future of Analytics: Multichannel Attribution
Webinar: Experts Weigh in on the State of WordPress for 2017
Webinar: AngularJS and the WordPress REST API
Ad

Similar to Webinar: AngularJS and the WordPress REST API (20)

PDF
Introduction of angular js
PPTX
AngularJS for Java Developers
ODP
WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
PDF
Introduction to angular js
PDF
AngularJS Workshop
PDF
243329387 angular-docs
PPT
Building Single Page Application (SPA) with Symfony2 and AngularJS
PDF
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
PDF
Dive into AngularJS and directives
PDF
Course CodeSchool - Shaping up with Angular.js
ODP
AngularJs Crash Course
PPTX
Basics of AngularJS
PDF
[Bristol WordPress] Supercharging WordPress Development
PDF
Nicolas Embleton, Advanced Angular JS
PDF
Sprint 17
PPTX
Building ColdFusion And AngularJS Applications
PPTX
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
PDF
Writing Gadgets with the WSO2 Gadget Server
PDF
Introduction to AngularJS
PDF
GDayX - Advanced Angular.JS
Introduction of angular js
AngularJS for Java Developers
WordPress as a Platform - talk to Bristol Open Source Meetup, 2014-12-08
Introduction to angular js
AngularJS Workshop
243329387 angular-docs
Building Single Page Application (SPA) with Symfony2 and AngularJS
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Dive into AngularJS and directives
Course CodeSchool - Shaping up with Angular.js
AngularJs Crash Course
Basics of AngularJS
[Bristol WordPress] Supercharging WordPress Development
Nicolas Embleton, Advanced Angular JS
Sprint 17
Building ColdFusion And AngularJS Applications
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Writing Gadgets with the WSO2 Gadget Server
Introduction to AngularJS
GDayX - Advanced Angular.JS

More from WP Engine (20)

PDF
More Dev. Less Drama.pdf
PDF
Why the Edge Isn't an Edge Case.pdf
PDF
Post eCommerce Site Launch- Optimizing Your Conversion Rate.pdf
PDF
Demo - New Features for Atlas.pdf
PDF
Debunking The Myths of Migration.pdf
PDF
Keeping Your WordPress Sites Safe Amidst A Rise in Global Cyberattacks.pdf
PDF
Building WordPress eCommerce at Scale .pdf
PDF
When to Choose Headless for Clients.pdf
PDF
Best Practices for Site Deployment With Local.pdf
PDF
Site Monitoring: The Intersection of Product, UX Design & Research .pdf
PDF
Front End: Building Future-Proof eCommerce Sites.pdf
PDF
Gutenberg and Headless WordPress.pdf
PDF
Blueprints and Other Local Features for Agencies.pdf
PDF
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...
PDF
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf
PDF
Headless 101 for WordPress Developers.pdf
PDF
Be the Change: The Future of WordPress with WP Engine's Developer Relations Team
PDF
An Atlas of Atlas.pdf
PDF
2022 – Year of the WordPress Developer.pdf
PDF
Using WooCommerce to Scale Your Store
More Dev. Less Drama.pdf
Why the Edge Isn't an Edge Case.pdf
Post eCommerce Site Launch- Optimizing Your Conversion Rate.pdf
Demo - New Features for Atlas.pdf
Debunking The Myths of Migration.pdf
Keeping Your WordPress Sites Safe Amidst A Rise in Global Cyberattacks.pdf
Building WordPress eCommerce at Scale .pdf
When to Choose Headless for Clients.pdf
Best Practices for Site Deployment With Local.pdf
Site Monitoring: The Intersection of Product, UX Design & Research .pdf
Front End: Building Future-Proof eCommerce Sites.pdf
Gutenberg and Headless WordPress.pdf
Blueprints and Other Local Features for Agencies.pdf
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf
Headless 101 for WordPress Developers.pdf
Be the Change: The Future of WordPress with WP Engine's Developer Relations Team
An Atlas of Atlas.pdf
2022 – Year of the WordPress Developer.pdf
Using WooCommerce to Scale Your Store

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 3 Spatial Domain Image Processing.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Programs and apps: productivity, graphics, security and other tools
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25-Week II
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx

Webinar: AngularJS and the WordPress REST API

  • 1. Technical Deep Dive into AngularJS and the WordPress REST API March 16th, 2016 #wprestapi Vote for your favorite plugins: www.pluginmadness.com
  • 2. Ask Questions as We Go! Please use the “Questions” pane throughout the webinar #wprestapi Slides and recording will be made available shortly after the webinar
  • 3. What We’ll Discuss Building on last webinar: The WP REST API as a Springboard for Website Greatness ❖ How to make custom admin interfaces using REST API and AngularJS ❖ Angular basics with the WordPress REST API ❖ Build a plugin admin screen (Ingot A/B testing) #wprestapi
  • 4. Quick Intros! #wprestapi Josh Pollock Owner/Developer, CalderaWP and Ingot @josh412 ❖ CalderaWP.com ❖ IngotHQ.com ❖ JoshPress.net Anthony Burchell Operations Engineer, WP Engine @antpb ❖ Started on WordPress 2.8 ❖ Casual Core Contributor ❖ Antpb.com ❖ Synth nerd
  • 5. Is this the new way?
  • 6. What is the benefit? ● Respects standards & separation of concerns ● Relatively easy to learn ● Testable ● Someone else pays to maintain it. #thanksgoogle
  • 8. Custom or Default Routes #wprestapi Use Default Routes ❖ Install the plugin ❖ https://wordpress.org/plugins/r est-api/ Make Your Own Endpoints ❖ Make your own API with WordPress 4.4+ ❖ Talk: video, slides & links ❖ Torque Article
  • 11. MVCModel The model is the current set of data, defined by the controller, displayed by the view.
  • 12. MVC$scope Current state of the model. Defined in controller - used in view.
  • 13. MVCView ● The visual representation of the data. ● In Angular this is an HTML file.
  • 14. MVCController ● Keeps the models up-to- date using the remote API. ● Updates the model based on your interactions with the view.
  • 16. MVCBindings ● Connects views to controllers. ● HTML5 Attributes ● Template Tags: Curly Brackets <div ng-controller="postExample"> <form> <input type="text" ng-model="post.title" /> </form> <div>{{post.title}}</div> </div> Controller
  • 17. MVCBindings ● Use controller function to create controller... ● $scope is available in view Template (function(angular) { 'use strict'; angular.module('learnAngular', []) .controller('postExample', ['$scope', function($scope) { $scope.post = { title: 'Enter Title' }; }]); })(window.angular);
  • 18. MVCBindings ● Bindings can be used to call functions ● Examples: ○ ng-submit ○ ng-hide Views <div ng-controller="postExample"> <form ng-submit="submit()"> <input type="text" ng-model="post.title" /> <input type="submit" value="Save" ng- hide="post.title == 'Enter Title'" /> </form> <div>{{post.title}}</div> </div>
  • 19. MVCBindings ● Define functions for view on $scope. ● Example: $scope.submit Controller (function(angular) { 'use strict'; angular.module('learnAngular', []) .controller('postExample', ['$scope', function($scope) { $scope.post = { title: 'Enter Title' }; $scope.submit = function(){ alert( 'saving' ); } }]); })(window.angular);
  • 20. MVCBindings ● ng-repeat: ○ Repeat items (like a list of posts) Views <div ng-controller="postsExample"> <h3>Posts:</h3> <div ng-repeat="post in posts"> {{post.title}} </div> </div>
  • 21. MVCBindings ● Look mom, two controllers! ● Iterating over posts array. (function(angular) { 'use strict'; angular.module('learnAngular', []) .controller('postExample', ['$scope', function($scope) { $scope.post = { title: 'Enter Title' }; $scope.submit = function(){ alert( 'saving' ); } }]).controller('postsExample', ['$scope', function($scope) { $scope.posts = [ { title: 'Post One' }, { title: 'Post Two' } ]; }]); })(window.angular);
  • 22. Making your own Super Fast Super Fancy Admin Interface! Or….
  • 23. SFSFAI! This is going to catch on... Making your own Super Fast Super Fancy Admin Interface!
  • 24. MVCAngular UI Router ● What URL uses what controller and template? ● http://jpwp.me/ingot-router ingotApp.config(function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/"); $stateProvider //click tests .state('clickTests', { url: "/click-tests", templateUrl: INGOT_ADMIN.partials + "/click-groups.html" }) .state('clickTests.list', { url: "/click-tests/all", templateUrl: INGOT_ADMIN.partials + "/list.html", controller: 'clickGroups' } ) .state('clickTests.edit', { url: "/click-tests/edit/:groupID", templateUrl: INGOT_ADMIN.partials + "/click-group.html", controller: 'clickGroup' } ) .state('clickTests.new', { url: "/click-tests/new", templateUrl: INGOT_ADMIN.partials + "/click-group.html", controller: 'clickGroup' } ) });
  • 25. MVCStart it up ● Include dependencies ● Adding translations to $rootScope var ingotApp = angular.module('ingotApp', [ 'ui.router', 'ui.bootstrap', 'colorpicker.module', 'ngAria', 'ngResource', 'ngclipboard', 'ngSanitize' ] ) .run( function( $rootScope, $state ) { $rootScope.translate = INGOT_TRANSLATION; $rootScope.partials_url = INGOT_ADMIN.partials; } );
  • 26. MVCAngular $http ● Similar to jQuery AJAX ● Use to update $scope and $state ingotApp.controller( 'clickDelete', ['$scope', '$http', '$stateParams', '$state', function( $scope, $http, $stateParams, $state ){ $http({ url: INGOT_ADMIN.api + 'groups/' + $stateParams.groupID + '?_wpnonce=' + INGOT_ADMIN.nonce, method:'DELETE', headers: { 'X-WP-Nonce': INGOT_ADMIN.nonce } } ).then( function successCallback() { swal( INGOT_TRANSLATION.deleted, "", "success" ); $scope.group = {}; $state.go('clickTests.list' ); }, function errorCallback( response ) { var data = response.data; var text = INGOT_TRANSLATION.sorry; if( _.isObject( data ) && _.isDefined( data.message ) ){ text = data.message; } $state.go('clickTests.list' ); } ); }]);
  • 27. MVCFactories ● Reusable code for HTTP ● Makes data an injected dependency -- easily mocked/ modified ● http://jpwp.me/ingot-factory ingotApp.factory( 'groupsFactory', function( $resource ) { return $resource( INGOT_ADMIN.api + 'groups/:id', { id: '@id', _wpnonce: INGOT_ADMIN.nonce, context: 'admin' },{ 'query' : { transformResponse: function( data, headers ) { var response = { data: data, headers: headers() }; return response; } }, 'update':{ method:'PUT', headers: { 'X-WP-Nonce': INGOT_ADMIN.nonce } },
  • 28. MVCFactories ● Think of it as your own API client ● http://jpwp.me/ingot-factory- in-use ingotApp.controller( 'clickGroups', ['$scope', '$http', 'groupsFactory', '$sce', function( $scope, $http, groupsFactory, $sce ) { var page_limit = 10; $scope.description = $sce.trustAsHtml( INGOT_TRANSLATION.descriptions.click ); groupsFactory.query( { page: 1, limit: page_limit, context: 'admin', type: 'click' }, function ( res ) { if ( res.data.indexOf( 'No matching' ) > -1 ) { $scope.groups = {}; return; }; $scope.groups = JSON.parse( res.data ); var total_groups = parseInt( res.headers[ 'x-ingot-total' ] ); var total_pages = total_groups / page_limit; $scope.total_pages = new Array( Math.round( total_pages ) ); $scope.groups.shortcode = []; } ); }]);
  • 29. Resources ❖eBook: The Ultimate Guide to the WordPress REST API http://wpeng.in/rest-api-ebook/ ❖Article: Basics of AngularJS with the WordPress REST API http://torquemag.io/2016/02/basics-of-angularjs-with-the-wordpress-rest- api/ ❖Building Apps with the WordPress REST API https://learn.joshpress.net/downloads/building-apps-wordpress-rest-api/ ❖Creating a Javascript Single Page App in the WordPress Dashboard http://torquemag.io/2015/12/creating-javascript-single-page-app-wordpress- dashboard/ #wprestapi
  • 30. CalderaWP REST API Course CalderaWP.com Q&A Feel free to ask away in the “Questions” pane! Are you an agency or freelancer? ● Finish more sites in less time ● Unlimited staging installs for WordPress projects for as little as $29 per month. Ask about qualifying for a listing in our online consultants’ directory! Call +1-512-827-3500, or Chat with us wpengine.com
  • 31. Myths, Mistakes & Management of WooCommerce at Scale Wednesday, April 13th, 12 pm EDT/ 11 am CDT/ 9 am PDT/ 5 pm GMT+1 Register Now! http://wpeng.in/woo/ ❖ Myths associated with scaling WooCommerce ❖ Mistakes and how to avoid them ❖ How to pick development and hosting partners Next Next Webinar