Use Angular JS in Visualforce Page.

Posted on December 30, 2020 Post Thumbnail

Hi Trailblazers, In this blog post I'm going to share some information about, How you can use Angular JS with Visualforce to show records onto your Visualforce Page.

Before we start :)

What is AngularJS ?

AngularJS is a JavaScript-based open-source front-end web framework .The

AngularJS framework works by first reading the Hypertext Markup Language (HTML) page,

which has an additional custom HTML attributes embedded into it.It can be added to an

HTML page with a <script> tag.

AngularJS is distributed as a JavaScript file, and can be added to a web page

with a script tag:

<script src="></script>

AngularJS Extends HTML :

AngularJS extends HTML with ng-directives.AngularJS modules define applications

➔ The ng-app directive defines an AngularJS application.

➔ The ng-controller  directive defines the controller.

➔ The ng-model directive defines how to bind the value of HTML controls

(input, select, textarea) to application data.

➔ The ng-bind directive binds application data to the HTML view.

Let's have a look on the following code.

In following code, We used Scope Object to bind the controller and view.

<!DOCTYPE html>


<script src=""></script>


<div ng-app="FirstApp" ng-controller="myCtrl">

Enter Your First Name: <input type="text" ng-model="firstName"><br>

Enter Your Last Name: <input type="text" ng-model="lastName"><br>


Full Name: {{firstName + " " + lastName}}



var app = angular.module('FirstApp', []);

app.controller('myCtrl', function($scope) {

$scope.firstName= "Asif";

$scope.lastName= "Aly";





After rendering above code.

After rendering above code.

It is all about AngularJs

Now let's talk about how we can implement this in the Visualforce page.

Why AngularJS in Visualforce Page?

It supports 2 way data binding, SPA( Single page Application ) and It requires less code.

Let's Start.

Let us see an example of AngularJS with Visualforce page:

In which we fetch all the Contacts

Here is the Code for Vf page:

<apex:page standardStylesheets="false" sidebar="false"

showHeader="false" applyBodyTag="false" applyHtmlTag="false"

docType="html-5.0" controller="AngularJswithvfController">

<html lang="en" ng-app="myApp">


<meta charset="utf-8"/>

<meta name="viewport" content="width=device-width, initial-scale=1"/>

<title>Angular Demo</title>

<link rel="stylesheet"





var App = angular.module('myApp', []);

App.controller('myctrl', function ($scope) {

$scope.contacts = {!contacts}




<body class="container" ng-controller="myctrl">


<h3 align="center" style="color:Black;"> Angular JS With Visualforce</h3>


<table class="table table-bordered" id="table" >






<tr ng-repeat="contact in contacts | filter:query">









Here is the code for the controller:

Public with sharing class AngularJswithvfController {

public static String getContacts() {

return JSON.serialize([select id, name, email

from contact ]);



After previewing above Visualforce Page.


As you can see, It's working now.

This is how we can use Angular JS with Visualforce Pages.

I hope It'll help you somehow.

If you have any question Ask Me

Thanks for Reading :)

Write a comment for suggestions and hit the heart icon.



There are no comments yet.
Your message is required.

Get notified of new posts