API for collections

API reference for Angular CDK collections

Import symbols from @angular/cdk/collections

Class to coordinate unique selection based on name. Intended to be consumed as an Angular service. This service is needed because native radio change events are only fired on the item currently being selected, and we still need to uncheck the previous selection.

This service does not store any IDs and names because they may change at any time, so it is less error-prone if they are simply passed through when the events occur.

Methods
listen

Listen for future changes to item selection.

Parameters

listener

UniqueSelectionDispatcherListener

Returns
() => void

Function used to deregister listener

notify

Notify other items that selection for the given name has been set.

Parameters

id

string

ID of the item.

name

string

Name of the item.

DataSource wrapper for a native array.

Methods
connect
Returns
Observable<readonly T[]>

disconnect
Methods
connect

Connects a collection viewer (such as a data-table) to this data source. Note that the stream provided will be accessed during change detection and should not directly change values that are bound in template views.

Parameters

collectionViewer

CollectionViewer

The component that exposes a view over the data provided by this data source.

Returns
Observable<readonly T[]>

Observable that emits a new value when the data changes.

disconnect

Disconnects a collection viewer (such as a data-table) from this data source. Can be used to perform any clean-up or tear-down operations when a view is being destroyed.

Parameters

collectionViewer

CollectionViewer

The component that exposes a view over the data provided by this data source.

Class to be used to power selecting one or more options from a list.

Properties
Name Description

changed: Subject<SelectionChange<T>>

Event emitted when the value has changed.

compareWith: (o1: T, o2: T) => boolean

selected: T[]

Selected values.

Methods
clear

Clears all of the selected values.

Parameters

flushEvent

boolean = true

Whether to flush the changes in an event. If false, the changes to the selection will be flushed along with the next event.

Returns
boolean | void

Whether the selection changed as a result of this call

deselect

Deselects a value or an array of values.

Parameters

values

The values to deselect

...values

T[]

Returns
boolean | void

Whether the selection changed as a result of this call

hasValue

Determines whether the model has a value.

Returns
boolean

isEmpty

Determines whether the model does not have a value.

Returns
boolean

isMultipleSelection

Gets whether multiple values can be selected.

isSelected

Determines whether a value is selected.

Parameters

value

T

Returns
boolean

select

Selects a value or an array of values.

Parameters

values

The values to select

...values

T[]

Returns
boolean | void

Whether the selection changed as a result of this call

setSelection

Sets the selected values

Parameters

values

The new selected values

...values

T[]

Returns
boolean | void

Whether the selection changed as a result of this call

sort

Sorts the selected values based on a predicate function.

Parameters

predicate?

(a: T, b: T) => number

toggle

Toggles a value between selected and deselected.

Parameters

value

T

The value to toggle

Returns
boolean | void

Whether the selection changed as a result of this call

Interface for any component that provides a view of some data collection and wants to provide information regarding the view and any changes made.

Properties
Name Description

viewChange: Observable<ListRange>

A stream that emits whenever the CollectionViewer starts looking at a new portion of the data. The start index is inclusive, while the end is exclusive.

Interface for a class that can flatten hierarchical structured data and re-expand the flattened data back into its original structure. Should be used in conjunction with the cdk-tree.

Methods
expandFlattenedNodes

Expands a flattened array of data into its hierarchical form using the provided expansion model.

Parameters

nodes

T[]

expansionModel

SelectionModel<T>

Returns
T[]

flattenNodes

Transforms a set of hierarchical structured data into a flattened data array.

Parameters

structuredData

any[]

Returns
T[]

nodeDescendents

Put node descendants of node in array. If onlyExpandable is true, then only process expandable descendants.

Parameters

node

T

nodes

T[]

onlyExpandable

boolean

isDataSource

Checks whether an object is a data source.

Parameters

value

any

Returns
value is DataSource<any>

type UniqueSelectionDispatcherListener = (id: string, name: string) => void;

Represents a range of numbers with a specified start and end.

type ListRange = {
    start: number;
    end: number;
};
Azure & Blue theme selected.