填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

QueryList

一个不可修改的条目列表,当应用状态变化时,Angular 会保证它是最新的。

An unmodifiable list of items that Angular keeps up to date when the state of the application changes.

查看"说明"...

      
      class QueryList<T> implements Iterable {
  constructor(_emitDistinctChangesOnly: boolean = false)
  dirty: true
  length: number
  first: T
  last: T
  changes: Observable<any>
  __@iterator: () => Iterator<T>
  get(index: number): T | undefined
  map<U>(fn: (item: T, index: number, array: T[]) => U): U[]
  filter(fn: (item: T, index: number, array: T[]) => boolean): T[]
  find(fn: (item: T, index: number, array: T[]) => boolean): T | undefined
  reduce<U>(fn: (prevValue: U, curValue: T, curIndex: number, array: T[]) => U, init: U): U
  forEach(fn: (item: T, index: number, array: T[]) => void): void
  some(fn: (value: T, index: number, array: T[]) => boolean): boolean
  toArray(): T[]
  toString(): string
  reset(resultsTree: (any[] | T)[], identityAccessor?: (value: T) => unknown): void
  notifyOnChanges(): void
  setDirty()
  destroy(): void
}
    

说明

ContentChildrenQueryList所提供对象的类型。

The type of object that ViewChildren, ContentChildren, and QueryListprovide.

ViewChildren

实现一个可迭代接口,因此它可以用于 ES6 JavaScript 的 for (var i of items) 循环,和 Angular 模板中的 *ngFor="let i of myList"

Implements an iterable interface, therefore it can be used in both ES6 javascript for (var i of items) loops as well as in Angular templates with *ngFor="let i of myList".

可以通过订阅 changes 这个 Observable 来监听这些变化。

Changes can be observed by subscribing to the changes Observable.

注意:将来此类将会实现 Observable 接口。

NOTE: In the future this class will implement an Observable interface.

Further information available in the Usage Notes...

构造函数

      
      constructor(_emitDistinctChangesOnly: boolean = false)
    
参数
_emitDistinctChangesOnly boolean
可选. 默认值是 `false`.

属性

属性说明
dirty: true只读
length: number只读
first: T只读
last: T只读
changes: Observable<any>只读

Returns Observable of QueryList notifying the subscriber of changes.

__@iterator: () => Iterator<T>

方法

返回位于 index 处的 QueryList 条目。

Returns the QueryList entry at index.

      
      get(index: number): T | undefined
    
参数
index number
返回值

T | undefined

参见 Array.map

See Array.map

      
      map<U>(fn: (item: T, index: number, array: T[]) => U): U[]
    
参数
fn (item: T, index: number, array: T[]) => U
返回值

U[]

参见 Array.filter

See Array.filter

      
      filter(fn: (item: T, index: number, array: T[]) => boolean): T[]
    
参数
fn (item: T, index: number, array: T[]) => boolean
返回值

T[]

参见 Array.find

See Array.find

      
      find(fn: (item: T, index: number, array: T[]) => boolean): T | undefined
    
参数
fn (item: T, index: number, array: T[]) => boolean
返回值

T | undefined

参见 Array.reduce

See Array.reduce

      
      reduce<U>(fn: (prevValue: U, curValue: T, curIndex: number, array: T[]) => U, init: U): U
    
参数
fn (prevValue: U, curValue: T, curIndex: number, array: T[]) => U
init U
返回值

U

参见 Array.forEach

See Array.forEach

      
      forEach(fn: (item: T, index: number, array: T[]) => void): void
    
参数
fn (item: T, index: number, array: T[]) => void
返回值

void

参见 Array.some

See Array.some

      
      some(fn: (value: T, index: number, array: T[]) => boolean): boolean
    
参数
fn (value: T, index: number, array: T[]) => boolean
返回值

boolean

以数组形式返回内部结果列表的副本。

Returns a copy of the internal results list as an Array.

      
      toArray(): T[]
    
参数

没有参数。

返回值

T[]

      
      toString(): string
    
参数

没有参数。

返回值

string

更新查询列表中存储的数据,并将 dirty 标志重置为 false,以便当检测到变更时,除非发生新变更,否则不会通知这些查询的变更。

Updates the stored data of the query list, and resets the dirty flag to false, so that on change detection, it will not notify of changes to the queries, unless a new change occurs.

      
      reset(resultsTree: (any[] | T)[], identityAccessor?: (value: T) => unknown): void
    
参数
resultsTree (any[] | T)[]

要存储的查询结果

The query results to store

identityAccessor (value: T) => unknown

Optional function for extracting stable object identity from a value in the array. This function is executed for each element of the query result list while comparing current query list with the new one (provided as a first argument of the reset function) to detect if the lists are different. If the function is not provided, elements are compared as is (without any pre-processing).

可选. 默认值是 `undefined`.
返回值

void

通过发出 changes EventEmitter来触发变更事件。

Triggers a change event by emitting on the changes EventEmitter.

      
      notifyOnChanges(): void
    
参数

没有参数。

返回值

void

internal

      
      setDirty()
    
参数

没有参数。

internal

      
      destroy(): void
    
参数

没有参数。

返回值

void

使用说明

例子

Example

      
      @Component({...})
class Container {
  @ViewChildren(Item) items:QueryList<Item>;
}