
Hello everyone!
I am Madhuri, a ServiceNow expert working at Palni India Pvt Ltd. With extensive experience in collaborating with customers across various domains, I have successfully delivered numerous ServiceNow implementations. I specialize in developing Service Portals and implementing Employee Central, ensuring an excellent user experience in every project.
I'm excited to talk about the most important and commonly used concepts of AngularJS that play a crucial role in ServiceNow widget development. In this series of "concepts of AngularJS for ServiceNow" I will cover key topics such as
Expressions
Directives
Scopes
Filters
Tables
using clear and practical examples. By the end, you'll have a good understanding of using AngularJS in ServiceNow, and you'll feel more confident in developing scripts.
I am eager to share this knowledge with you and assist you in maximizing the potential of AngularJS in your ServiceNow projects. Let's embark on this learning journey together!
Thanks for watching!
Hello everyone!
Today let's talk about the expressions in Angularjs.
AngularJS expressions are similar to JavaScript expressions that connect data with HTML.
Firstly, let's see the binding of the data using double braces:
For example:
<p>{{6+6}}</p> - for calculations
Output - 12
Now, let's try the same calculation using the ng-bind directive.
Example:
<p ng-bind="6+6"></p>
Output - 12
You can observe that both were giving the same output. This clearly says,
the expressions can be written in 2 ways:
- using double braces or
- using a 'ng-bind' directive
Double braces were - {{}} - also termed as Interpolation.
Directives contains 'ng-' as the prefix.
Let's explore few more examples for binding data.
1. Arithmetic operations:
<p> {{10 + 5}}<p> (addition, subtraction,division)
2. Strings:
<div ng-init="firstName = 'Palni'; lastName = 'Inc'">
<p>Hello, {{firstName + " " + lastName}}</p>
</div>
3. Objects:
<div ng-init="company={name:'Palni', clients:50}">
<p>Name: {{ company.name }}</p>
<p>Clients: {{ company.clients }}</p>
</div>
4. Arrays:
<div ng-init="runs = [6,4,2,4,1,3]">
<p>scored runs in 3rd ball - {{runs[2]}}</p>
</div>
5.Dynamic CSS with Expressions:
<div ng-init="myBackgroundColor='skyblue'; myColor='red'">
<input style="background-color:{{ myBackgroundColor }}">
<p style="color:{{ myColor }}">The color is {{ myColor }}</p>
</div>
6.Images:
<div ng-init="image = 'https://static.wanderon.in/wp-content/uploads/2023/08/untitled-design-2023-08-24t102229.527-min.png'">
<img src="{{image}}" width="400"/>
</div>
Lastly, Expressions do not support any control statements like loops or conditions.
The only exception is the ternary operator.
Example:
<div ng-init="a=5;b=4">
<p>{{a==b ? "equal":"not equal"}}</p>
</div>.
This is because we use controllers, i.e., client scripts, to write advanced/complex logic for the application.
Also, unlike the javascript expressions which throw an error if it doesn't find its value, expressions return the value as undefined if it doesn't find its value.
I hope these examples help you understand binding data to HTML using expressions.
In the upcoming video, I'll be covering the directives with simpler examples.
Thanks for Watching!
Hello everyone!
Today, I'll explain what is data binding in AngularJS and how it works? I'll also give some examples to help you understand its usage.
Before we begin, let's quickly review AngularJS expressions.
Expressions help to perform calculations, combine data, or display information dynamically on the HTML / Client
To learn more about expressions a link is provided in the description below.
Now lets understand What is databinding?
Data binding is a way to automatically synchronize data between the model and the view. Data binding can be implemented one-way or two-way.
One-way data binding means data flows in one direction, typically from the model (JavaScript) to the view (HTML).
Let’s understand this with a simple example:
//Client script:
$scope.fruits=["Apple","Berries","Cherry"]
//HTML:
<p> {{fruits[2]}} </p>
When you run this code, you will see the output as Cherry in the preview.
Here, you can notice the $scope object in the client script. view can dynamically access the $scope object from the client script.
We will be discussing about the $scope object in detail in our upcoming videos.
/*Explain the difference between expression and data binding */
Here are a few important considerations to keep in mind regarding one-way data binding:
It’s a Unidirectional Flow: In this example, the data flows from the model ($scope.fruits) to the view (the HTML). If you change the contents of the fruits array in the JavaScript code, the displayed value will update accordingly.
No Update from View to Model: If you were to change the displayed text directly in the HTML (e.g., by editing it), it would not affect the underlying model. The model remains unchanged unless explicitly modified in the controller.
THIS IS NOT EXPLAINED IN THE EXAMPLE.... GIVE AN EXAMPLE TO THE ABOVE STATEMENT AND SHOW IT PRACTICALLY
Two-way:
Two-way data binding allows data to flow in both directions: from the model to the view and from the view back to the model.
Lets Look at an example
//Client script:
$scope.person = { firstName: 'Sunitha', lastName: 'Williams' };
//HTML:
EXPLAIN THIS SAME EXAMPLE WITH ONE-WAY
<p>First Name: <input type="text"></p> <p>Last Name: <input type="text"></p> <p>Full Name: {{ person.firstName + ' ' + person.lastName }}</p>
"SEE ALWAYS THE DATA IS COMING FROM THE MODEL TO VIEW AND IF I UPDATE ANYTHING IN THE VIEW IT IS NOT UPDATING ON THE MODEL"
NOW LETS CHANGE IT TO TWO DAT BINDING
<p>First Name: <input type="text" ng-model="person.firstName"></p> <p>Last Name: <input type="text" ng-model="person.lastName"></p> <p>Full Name: {{ person.firstName + ' ' + person.lastName }}</p>
When you run this code:
If you type "John" in the first name field, it will display "Your full name is: John " (with a space).
If you then type "Doe" in the last name field, it will update to "Your full name is: John Doe".
As we bind the input field with the object in model using ng-model it automatically updates the model and returns the value to the View.
The ng-model directive binds the value of HTML form elements (like <input>, <select>, and <textarea> EXPLORE AND LIST ALL THE ELEMENTS) to a variable defined in the $scope object.
Hello ALl, Previously we learned about Expressions and Data binding. Today i'll explain about AngularJS directives.
Directives are special instructions that enhance web pages HTML (view) / Widget by making them interactive and responsive to user actions.
Let's begin with `ng-init` directive
This directive is essential for setting up initial variable values that can be utilized throughout the application. For instance:
```html
<div ng-init="name='Paul'">
<p>Hello, {{ name }}!</p>
</div>
```
In this example, the `ng-init` directive assigns the value 'Alice' to the variable `name`. Consequently, the paragraph displays "Hello, Alice!", demonstrating how the directive can initialize variables for use in HTML.
moving on to **ng-bind Directive**: it connects a specified expression to an HTML element, automatically updating the displayed content as the expression changes.
- Example:
```html
<div ng-init="msg='Welcome to ServiceNow!'">
<p ng-bind="msg"></p> <!-- Binds the msg variable -->
</div>
```
In this example, the directive `ng-init` initializes a variable `msg` with the string "Welcome to ServiceNow!". The `ng-bind` directive then binds this variable to the paragraph element, automatically displaying the message.
Let’s experiment further with a mathematical expression:
```html
<p ng-bind='10/2'></p>
```
This will evaluate the expression and render the output as 5.
Now, if we use the same expression within curly braces:
```html
<p> {{ 10 / 2 }}</p>
```
This also displays 5, confirming that both the `ng-bind` directive and the curly braces syntax yield identical results. This similarity in output illustrates that they function in the same way by evaluating expressions and displaying their results seamlessly on the web page.
3.`ng-model` allows you to bind the value of HTML form elements, such as input fields, select boxes, and text areas, to a variable in your application’s scope. This creates two-way data binding, meaning that changes made in the input field will automatically update the bound variable, and vice versa.
**Example:**
```html
<p>Enter your name:</p>
<input type="text" ng-model="userName"> <!-- Binding the input to the userName variable -->
<p>Your name is: {{ userName }}</p> <!-- Displaying the value of userName -->
```
4. The `ng-repeat` directive is used to iterate over collections, such as arrays or objects, to dynamically generate HTML content for each item.
For example:
// HTML:
```html
$scope.names = ['John', 'Jhanvi', 'Moksha', 'James'];
```
// Client Script:
```html
<ul>
<li ng-repeat="name in names">{{name}} </li>
</ul>
```
This process will create a visually organized list, with each name from the array presented as an individual list item. If you found this tutorial informative and beneficial, please consider liking the video and subscribing for more in-depth tutorials on AngularJS and various other web technologies.
Thank you for watching!
Hello All,
Starting with ng-if Directive
It removes or recreates portions of the DOM based on the truthiness of an expression. If the expression evaluates to true, the element is added to the DOM; if it evaluates to false, the element is removed completely, along with its child elements and associated state
Ex:
1.
<input type="checkbox" ng-model="myVar" ng-init="myVar = false">
<h1 ng-if="myVar">Welcome</h1>
2.
//Client Script:
$scope.products = [{
name: "Product1",
inStock: true
},
{
name: "Product2",
inStock: true
}]
//HTML:
<div ng-repeat="product in products">
<div ng-if="product.inStock">
{{product.name}} - Available
</div>
<div ng-if="!product.inStock">
{{product.name}} - Out of Stock
</div>
</div>
// Is it possible to use if-else or switch? explain it here
Moving on to ng-click:
it allows to define custom behaviors for HTML elements when user click on an object.
Ex:
<button ng-click="count = count + 1" ng-init="count=0">OK</button>
<p>{{count}}</p>
Next ng – select:
It allows to create dynamic and customizable dropdown lists by linking a `<select>` element to a model. This connection automatically populates the options based on the model's data, enhancing user experience with real-time updates.
Ex:
1.
//HTML:
<input type="checkbox" ng-model="mySel">
<p>My Topics:</p>
<select>
<option>Topic 1</option>
<option ng-selected="mySel">Topic 2</option>
<option>Topic 3</option>
</select>
Lastly ng-show/hide:
control the visibility of HTML elements based on the evaluation of expressions.
Ex:
<input type="checkbox" ng-model="myVar" ng-init="myVar = true">
<h1 ng-show="myVar">Welcome</h1>
To show the difference b/w ng-show and ng-if, let me show you an example,
Ex:
<input type="checkbox" ng-model="myVar" ng-init="myVar = true">
<h1 ng-show="myVar">Welcome</h1>
In the console, you can notice that when we checked the checkbox, it was only showing the element from the DOM.
Let’s replace the ng-show directive with the ng-if directive and see what happens in the DOM,
<input type="checkbox" ng-model="myVar" ng-init="myVar = false">
<h1 ng-if="myVar">Welcome</h1>
In the console, you can notice that when we uncheck the checkbox, it removes the element from the DOM.
This clearly says, that ng-if is used to remove the element from the DOM, and ng-show/hide is used to show/hide the element.
Take away here is
If there is a content that should only be loaded or rendered based on specific conditions (e.g., fetching data from a server), ng-if is appropriate because it will not load the content until the condition is true.
on other hand to show or hide elements frequently (e.g., in response to user actions like clicking buttons), use ng-show or ng-hide.
Thanks for Watching!
Hello everyone!
Today, I’ll give a quick demonstration on how to create and work with AngularJS tables in ServiceNow, with practical examples which are very frequetly used in widget development.
Having good knowledge on using AngularJS tables enables developers to display data on portals in ways that standard ServiceNow list views do not allow.
Lets consider a use-case "Develop a widget to Displays incident number, short description, priority, state & assigned to columns"
We shall write our script in server-side script to retrieve data from incident table.
By using GlideRecord API, incident records can be queried.
//Server Script:
(function() {
data.incidents = []; //here we are declaring an array within data object DO NOT SHOW THIS COMMENT ON SCREEN THIS IS JUST FOR YOU TO TELL WHILE TYPING THE SCRIPT
var gr = new GlideRecord('incident');
gr.addQuery('active','true');
gr.query(); //here we are querying the active incidents DO NOT SHOW THIS COMMENT ON SCREEN THIS IS JUST FOR YOU TO TELL WHILE TYPING THE SCRIPT
while (gr.next()) {
data.incidents.push({ // Populate incident array in data object with required columns and their values DO NOT SHOW THIS COMMENT ON SCREEN THIS IS JUST FOR YOU TO TELL WHILE TYPING THE SCRIPT
number: gr.number.getDisplayValue(),
short_description: gr.short_description.getDisplayValue(), // Added this line
priority: gr.priority.getDisplayValue(),
state: gr.state.getDisplayValue(),
assigned: gr.assigned_to.getDisplayValue(),
});
}
})();
In HTML Section lets create a table using ng-repeat directive to loop through each item in data.incidents array
//HTML:
<style>
table th,td{
padding: 1rem;
}
</style>
<table border="3px">
<tr>
<th>Number</th>
<th>Short Description</th>
<th>Priority</th>
</tr>
<tr ng-repeat="item in data.incidents"> //ng-repeat iterates through each incident in data.incidents, creating a row DO NOT SHOW THIS COMMENT ON SCREEN THIS IS JUST FOR YOU TO TELL WHILE TYPING THE SCRIPT
<td>{{ item.number }}</td>
<td>{{ item.short_description }}</td>
<td>{{ item.priority }}</td>
</tr>
</table>
Hello Everyone!
Scope is an object that stores variables and functions that can be used in HTML
It acts as a bridge between the client controller and the HTML structure that is rendered on the page.
scopes allow for dynamic data binding, ensuring that updates in the client-side data are automatically reflected on the HTML and vice versa.
Let’s look at an example
First, let me show how to pass a variable from client controller to HTML.
For this demonstration, I have created a widget called 'Scope Demo'
Let's create the client controller
api.controller = function ($scope) {
var c = this;
$scope.message = "This string is passed from the widget Client controller!";
};
let's create a HTML with a simple heading tag
HTML:
<div>
<h3>{{message}}</h3> <!-- This will display the message from $scope object in the client controller -->
</div>
Now let us look at an example that demonstrates how to pass values from HTML to the client controller
HTML:
<div>
<input type="text" ng-model="userInput" placeholder="Enter something..." />
<button ng-click="showAlert()">Submit</button>
</div>
Client-script:
api.controller = function ($scope) {
var c = this;
$scope.showAlert = function () {
alert('You have entered: ' + $scope.userInput); //this value is received from the HTML inputbox
};
};
Hello Everyone! Today let’s explore Angular filters.
What are Filters? In AngularJS, filters are generally used to modify the data.
Commonly used filters include – (use a presentation slide while showing the below filters masure some animation is there)
currency
date
filter
json
limitTo
lowercase
uppercase
number
orderBy.
Now, let’s try it out practically one by one.
Firstly currency,
<p>{{900 | currency}}
This will display the amount in US dollars with two decimal places.
Then date,
<p>
{{01-01-2025 | date}}
</p>
If we want to modify the format,
//client script:
$scope.myDate = new Date(2024, 11, 20);
//html:
<p>
{{ myDate | date : 'dd-MM-yyyy' }}
</p> //removed by Madhuri as it might be confusing.
Filter: select a subset of items from an array.
//client:
$scope.items = ["Apple","Cake","Berries","Cherry","Icecream","Peach"];
//html
<ul>
<li ng-repeat="item in items | filter:'r'">{{ item }}</li>
</ul>Here, items will be filtered based on searchTerm, displaying only matching items.
json: convert a JavaScript object into a JSON string
//client:
$scope.person = {
name: "John Doe",
age: 30,
city: "New York"
};
//html:
<p>{{ person | json }}</p>
LimitTo:
//client:
$scope.items = ["Apple","Cake","Berries","Cherry","Icecream","Peach"];
//html:
<ul>
<li ng-repeat="item in items | limitTo:3">{{ item }}</li>
</ul>
Uppercase:
<p>{{ "Madhuri" | uppercase }}</p>
Lowercase:
<p>{{ "Madhuri" | lowercase }}</p>
Number:
for formatting numeric values in a user-friendly way. It enhances readability by adding commas for thousands and allows for control over decimal precision.
<p>{{ 1000 | number }}</p>
orderBy:
//client:
$scope.people = [
{
name: "Alice",
location: "USA"
},
{
name: "Noor",
location: "India"
},
{
name: "Maria",
location: "Spain"
},
{
name: "Liam",
location: "Ireland"
},
{
name: "Chen",
location: "China"
}
];
//html:
<ul>
<li ng-repeat="x in people | orderBy:'location'">{{ x }}</li>
</ul>
This sorts items based on the specified property.
Thanks for watching!
AngularJS remains one of the most powerful tools for front-end development within ServiceNow, especially for creating dynamic and engaging user experiences in Service Portal, UI Pages, and custom interfaces. This course provides a comprehensive and practical introduction to AngularJS in the ServiceNow environment, enabling learners to build fully functional, data-driven applications that enhance usability and functionality across the platform.
Learners will begin with the foundational concepts of AngularJS, including modules, controllers, routing, data binding, services, and directives, before applying them directly within ServiceNow. The course then moves into hands-on development, showing how to design custom widgets, consume GlideRecord and Script Include data, integrate REST APIs, and create seamless interactions between client and server logic.
Through realistic examples, exercises, and guided builds, participants will learn not only how to write AngularJS code, but how to think like a ServiceNow front-end architect. The course emphasizes clean coding techniques, optimization, maintainability, troubleshooting, and structured development patterns that can be applied to production-grade solutions.
By the end, learners will be equipped with the skills and confidence to transform ServiceNow interfaces into modern, responsive, and highly interactive user experiences—delivering faster adoption, stronger engagement, and measurable business impact, and empowering you to deliver truly transformative, enterprise-grade ServiceNow experiences.