Angular + Salesforce

Building single page apps

Presented by Scott Covert / @scottbcovert

SPA vs MVC

This ain't your mama's app architecture

SPA Benefits

  • More fluid & responsive applications
  • Separates presentation layer from application logic
  • Plug & Play Backend/Frontend

SPA Disadvantages

  • Javascript dependency
  • SEO implications
  • Security

AngularJS

HTML enhanced for web apps!

AngularJS Components

Concept Description
Template HTML with additional markup
Directives extend HTML via custom attributes and elements
Scope context where the model is stored
Service reusable business logic independent of views
Controller the business logic behind views
Module a container for the different parts of an AngularJS app

AngularJS Benefits

  • Two-way data binding
  • Massive community
  • Dependency injection
  • Developer tools
  • Bidirectional Data Binding

    AngularJS Disadvantages

  • Opinionated
  • Esoteric Syntax & Terminology
  • Sample AngularJS App Template

    
    <!doctype html>
    <html lang="en" ng-app="phonecatApp">
    <head>
      
      Google Phone Gallery
      
      
      
      
    </head>
    <body ng-controller="PhoneListCtrl">
    
      
    Search: Sort by:
    • {{phone.name}}

      {{phone.snippet}}

    </body> </html>

    Sample AngularJS App Controller

    
    'use strict';
    
    /* Controllers */
    
    var phonecatApp = angular.module('phonecatApp', []);
    
    phonecatApp.controller('PhoneListCtrl', function($scope) {
      $scope.phones = [
        {'name': 'Nexus S',
         'snippet': 'Fast just got faster with Nexus S.',
         'age': 1},
        {'name': 'Motorola XOOMâ„¢ with Wi-Fi',
         'snippet': 'The Next, Next Generation tablet.',
         'age': 2},
        {'name': 'MOTOROLA XOOMâ„¢',
         'snippet': 'The Next, Next Generation tablet.',
         'age': 3}
      ];
    
      $scope.orderProp = 'age';
    });
    
    						

    Sample AngularJS App

    Live Demo

    AngularJS
    +
    Salesforce

    How To Connect AngularJS & Salesforce

    • Modules --> Served as Static Resource to VF Page
    • Templates --> Visualforce Page/Component Fragments
    • Services --> @RemoteAction Apex Methods
    • ngForce
    • Visualforce Remoting
    • jsForce

    Benefits To Connecting AngularJS & Salesforce

    • Live refresh
    • Simpler Apex Classes & Unit Testing
    • More powerful debugging tools
    • Salesforce1 Ready

    AngularJS vs Angular

    Key Changes

    • TypeScript
    • Component-based
    • Improved Performance & Tooling

    How To Connect Angular & Salesforce

    • Angular + Salesforce Boilerplate by Chris Watzon
    • Application & Node Modules --> Served as Static Resources to VF Page
    • Services --> @RemoteAction & WebService Apex Methods
    • Visualforce Remoting when on Salesforce, SOAP API for local development

    Salesforce Lightning