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
|
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:
|
If you run the above example it will produce output something like this β
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 Object | JSON Example
Let us create a simple example for Foreach object loop β
If you run the above example it will produce the output something like this β
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 β
If you run the above example it will produce the output something like this β
Compare two Objects in AngularJs Example:
You can compare two objects in angularjs as below β
Compare two Strings in AngularJs Example:
|
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-
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.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 :
|
If you run the above example it will produce output something like this β