angular.Array.add

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

Description

add is a function similar to JavaScript's Array#push method, in that it appends a new element to an array. The difference is that the value being added is optional and defaults to an empty object.

Note: this function is used to augment the Array type in angular expressions. See angular.Array for more info.

Dependencies

Usage

angular.Array.add(array[, value]);

Parameters

Returns

{Array}

The expanded array.

Example

This example shows how an initially empty array can be filled with objects created from user input via the $add method.

[<a href="" ng:click="people.$add()">add empty</a>] [<a href="" ng:click="people.$add({name:'John', sex:'male'})">add 'John'</a>] [<a href="" ng:click="people.$add({name:'Mary', sex:'female'})">add 'Mary'</a>] <ul ng:init="people=[]"> <li ng:repeat="person in people"> <input name="person.name"> <select name="person.sex"> <option value="">--chose one--</option> <option>male</option> <option>female</option> </select> [<a href="" ng:click="people.$remove(person)">X</a>] </li> </ul> <pre>people = {{people}}</pre>