Skip to content

Instantly share code, notes, and snippets.

AngularJS provides filters to transform data:
1. currency: Format a number to a currency format.
2. date: Format a date to a specified format.
3. filter: Select a subset of items from an array.
4. json: Format an object to a JSON string.
5. limitTo: Limits an array/string, into a specified number of elements/characters.
6. lowercase: Format a string to lower case.
7. number: Format a number to a string.
8. orderBy: Orders an array by an expression.
In AngularJS, a service is a function, or object, that is available for, and limited to, your AngularJS application.
AngularJS has about 30 built-in services. One of them is the $location service.
The $location service has methods which return information about the location of the current web page:
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $location) {
$scope.myUrl = $location.absUrl();
});
ng-blur
ng-change
ng-click
ng-copy
ng-cut
ng-dblclick
ng-focus
ng-keydown
ng-keypress
ng-keyup
input elements
select elements
button elements
textarea elements
Input fields have the following states:
$untouched The field has not been touched yet.
$touched The field has been touched.
$pristine The field has not been modified yet.
$dirty The field has been modified.
$invalid The field content is not valid.
$valid The field content is valid.
They are all properties of the input field, and are either true or false.
The following classes are added to, or removed from, input fields:
ng-untouched The field has not been touched yet
ng-touched The field has been touched
ng-pristine The field has not been modified yet
ng-dirty The field has been modified
ng-valid The field content is valid
ng-invalid The field content is not valid
ng-valid-key One key for each validation. Example: ng-valid-required, useful when there are more than one thing that must be validated
ng-invalid-key Example: ng-invalid-required
const Feact = {
createElement(type, props, children) {
const element = {
type,
props: props || {}
};
if (children) {
element.props.children = children;
}
Custom validations in Angular JS are created as directives with a dependency on the ng-model directive.
app.directive('evenNumber', function() {
return {
require: 'ngModel',
link: function(scope, element, attr, ctrl) {
function isEven(value) {
if (parseInt(value, 10) % 2 === 0) {
ctrl.$setValidity('even', true);
} else {
angular.lowercase() Converts a string to lowercase
angular.uppercase() Converts a string to uppercase
angular.isString() Returns true if the reference is a string
angular.isNumber() Returns true if the reference is a number
If you want to navigate to different pages in your application, but you also want the application to be a SPA (Single Page Application),
with no page reloading, you can use the ngRoute module.
Applications can only have one ng-view directive, and this will be the placeholder for all views provided by the route.
<div ng-view></div>
With the $routeProvider you can define what page to display when a user clicks a link.
var app = angular.module("myApp", ["ngRoute"]);