Created
February 6, 2015 20:37
-
-
Save jeffdonthemic/a0dcd4cb3608e4d51fc1 to your computer and use it in GitHub Desktop.
Hello Angular Visualforce Page & Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global with sharing class AngularDemoController { | |
// hardcode an account id for demo purposes | |
static String accountId = '0017000001CwYz9'; | |
global static String getAccount() { | |
return JSON.serialize([select name, billingstreet, | |
billingcity, billingstate, billingpostalcode | |
from account where id = :accountId][0]); | |
} | |
global static String getContacts() { | |
return JSON.serialize([select id, name, email | |
from contact where accountId = :accountId]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardStylesheets="false" sidebar="false" | |
showHeader="false" applyBodyTag="false" applyHtmlTag="false" | |
docType="html-5.0" controller="AngularDemoController"> | |
<html lang="en" ng-app="demoApp"> | |
<head> | |
<meta charset="utf-8"/> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<title>Angular Demo</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"/> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script> | |
<script> | |
// define the app | |
var demoApp = angular.module('demoApp', []); | |
// add the controller | |
demoApp.controller('DemoCtrl', function ($scope) { | |
$scope.account = {!account} | |
$scope.contacts = {!contacts} | |
}); | |
</script> | |
</head> | |
<body class="container" ng-controller="DemoCtrl"> | |
<h1>{{account.Name}}</h1> | |
<p class="lead"> | |
{{account.BillingStreet}}<br/> | |
{{account.BillingCity}}, {{account.BillingState}} | |
{{account.BillingPostalCode}} | |
</p> | |
<table class="table table-bordered"> | |
<tr> | |
<th>Name</th> | |
<th>Email</th> | |
<th>Id</th> | |
</tr> | |
<tr ng-repeat="contact in contacts"> | |
<td>{{contact.Name}}</td> | |
<td>{{contact.Email}}</td> | |
<td>{{contact.Id}}</td> | |
</tr> | |
</table> | |
</body> | |
</html> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment