Tag Archives: AngularJs Api tutorials

AngularJs check if date is valid


AngularJs check valid date : While working with dates in AngularJs we need to check whether the variable holds the valid date value or not. There are many ways to check for the valid date using AngularJs and JavaScript. You can use angular.isDate() to check a valid in AngularJs. Here in this tutorial we are going to explain how you can use AngularJs function angular.isDate() to check a date value. You can also use our online tool to run and edit the code.


AngularJs check valid date Example

You can check valid date as below-

JavaScript Part –

JavaScript Part Contains the following script –

AngularJs check valid date : JavaScript

 

The above function will test the date if date is invalid it will return false else it will return true.

Html Part-

Html Part Contains the following html –

AngularJs check valid date: Html Part



Result = {{result1}}

Result = {{result2}}

Complete Example-

Now let us combine both javascript and html parts. Here is the complete example –

How to check date is valid in AngularJs : Example:

 
 

  


Result = {{result1}}

Result = {{result2}}

Try it Β»

If you run the above example it will produce output something like this –

AngularJs check if date is valid

Angularjs deserialize json


Angularjs deserialize json [angular.fromJson()];- angular.fromJson() function is used to deserialize a json string in AngularJs. Here in this tutorial we are going to explain how you can use angular.fromJson in AngularJs. Let us go with syntax and example to see how we can parse json in AngularJs.


Angularjs deserialize json | angular.fromJson | Example

Syntax

Syntax for angular.fromJson function is –

Angularjs angular.fromJson | Syntax :

angular.fromJson(json);

Agruments

  • json – JSON string to be deserialize.

Return

This will return deserialized string.

Angularjs Foreach


Angularjs Foreach(angularjs.foreach)- angularjs.foreach is used to iterate object collection items which can be an object or an array. Here in this tutorial we are going to explain how you can use foreach loop in AngularJs. You can use our online demo try and edit the code online.


Angularjs Foreach Array | Objects | Example

Syntax

Syntax for angular.foreach function is –

Angularjs Foreach Array | Objects | Syntax :

angular.forEach(obj, iterator, [context]);

Agruments

  • obj – Object or array to iterate.
  • iterator – Iterator function.
  • context(optional) – Object to become context.

Return

This will retrun Reference to object or array.

Angularjs Foreach Array Example

Let us create a simple example for Foreach Array loop –

Angularjs Foreach Array Example:

 
 

  
Result = {{html}}

Try it Β»

Angularjs Foreach Object | JSON Example

Let us create a simple example for Foreach object loop –

Angularjs Foreach Object | JSON Example:





 
 

  
Result = {{html}}

Try it Β»

If you run the above example it will produce the output something like this –

Angularjs Foreach Array | Objects | Example  Syntax

angular.equals


angular.equals- This is used to check if two objects or two values are equal. It supports the value types, regular expressions, arrays and objects. Here in this tutorial we are going to explain how you can use this function to compare the two values, objects or arrays. You can use our online demo try and edit the code online.


angular.equals | compare strings | Array | Objects | Example

Two values or objects will be equal if one of the following condition is satisfied :

  • If Both values or objects are identical as per === comparison.
  • If Both objects or values are of the same type and all of its properties are equal using angular.equals.
  • If Both values are NaN.
  • If Both values are using the regular expression and they have same representation.

Syntax

Syntax for angular equals is –

AngularJs compare strings | Array | Objects :

angular.equals(object1, object2);

Agruments

  • object1 – Object or value for comparision
  • object2 – Object or value for comparision

Return

This will retrun true or false on the basis of comparision.

angular.equals Example

Let us create a simple example to compare two strings using this function –

Compare two Strings in AngularJs Example:

 
 

  
Value 1
Value 2

Result = {{result}}

Try it Β»

If you run the above example it will produce the output something like this –

angular.equals | compare strings | Array | Objects | Example

Compare two Objects in AngularJs Example:

You can compare two objects in angularjs as below –

Compare two Strings in AngularJs Example:

 
 

  
User 1 Name
Phone
User 1 Name
Phone

Result = {{result}}

Try it Β»

angular.element


angular.element Function – This function is basically alias for the jQuery. If jQuery is not available angular.element can be used. angular.element is built in sub set β€œjQuery”, which is called β€œjQuery lite” or β€œjQlite”

Here in this tutorial we are going to explain the angular.element with example and demo. You can use our online editor to edit and run the example.


angular.element Syntax | Example | Demo

Syntax

Syntax for the angular.element is given below –

Syntax:

angular.element(element);

Where element is DOM element.

Arguments

  • element – DOM element

AngularJs jqLite Available Functions

Following jQuery methods are avialable in jQlite –

  • addClass() – first argument Not supported as function.
  • after()
  • append()
  • attr() – parameters not supported as function.
  • bind() – namespaces, selectors or eventData not supported.
  • children() – selectors not supported.
  • clone()
  • contents()
  • css() – Only retrieves inline-styles, does not call getComputedStyle(). As a setter, does not convert numbers to strings or append β€˜px’, and also does not have automatic property prefixing.
  • data()
  • detach()
  • empty()
  • eq()
  • find() – Limited to lookups by tag name
  • hasClass()
  • html()
  • next() – selectors not supported.
  • on() – namespaces, selectors or eventData not supported.
  • off() – namespaces, selectors or event object as parameter not supported.
  • one() – namespaces or selectors not supported.
  • parent() – selectors not supported.
  • prepend()
  • prop()
  • ready()
  • remove()
  • removeAttr()
  • removeClass() – first argument not supported as function.
  • removeData()
  • replaceWith()
  • text()
  • toggleClass() – first argument not supported as function.
  • triggerHandler() – Passes a dummy event object to handlers.
  • unbind() – namespaces or event object as parameter not supported.
  • val()
  • wrap()

Example

Here is simple example of angular element function-

angular.element Example :

 
 

  

Angular Counter = {{counter}}

jQLite Counter = 0

Try it Β»

Here we have create an example which have both method to create function and call it. You run the above example to see how jQuery lite works in angularJs. If you run the above example it will produce output something like this –

angular.copy


angular.copy Function – It basically creates the copy of the source array or object. The syntax for angular copy function is angular.copy(source, [destination]); where source will be copied into destionation.
source and destionation both must be of the same type.

Here in this tutorial we are going to explain the ng function component with example and demo. You can use our online editor to edit and run the example.


angular.copy Syntax | Example | Demo

Syntax

Syntax of angular copy function is as –

angular.copy Syntax :

angular.copy(source, [destination]);

Arguments

  • source(Any Type) – Source to be copied. It can be any type – null, undefined or array.
  • destination(object or array) – Destination to which source to be copied. It must be object or array.

Example

Here is simple example of angular copy function-

angular.copy Example :

 
 

  



user = {{user | json}}
master = {{master | json}}


Try it Β»

angular.bind


angular.bind function – It basically returns a function(fn) which is bound to itself. You can also supply optional arguments that are prebound to the function.
Here is this tutorial we are going to explain how to use the angular.bind function with example and online demo.


angular.bind Function Example

Syntax

Syntax for the angular.bind is given below –

Syntax:

angular.bind(self, fn, args);

Arguments

  • self – In which context fn(function) should be evaluated.
  • fn – Function to be bound.
  • args– Optional arguments to be prebound to the fn function call.

Here is simple example of angular bind. In this example angular bind is used to bind the add function and the arguments – $scope.input1, $scope.input2 will be passed to the add function. The below example accepts two arguments and returns their addition –

angular.bind function example :

 
 

  
Enter a number 1.
Enter a number 2
number 1 + number 2 = {{result}}

Try it Β»

If you run the above example it will produce output something like this –