填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写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()
  dirty: true
  changes: Observable<any>
  length: number
  first: T
  last: T
  __@iterator: () => Iterator<T>
  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)[]): 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.

构造函数

constructor()
      
      constructor()
    
参数

没有参数。

属性

属性说明
dirty: true只读
changes: Observable<any>只读
length: number只读
first: T只读
last: T只读
__@iterator: () => Iterator<T>

方法

参见 Array.map

See Array.map

map<U>(fn: (item: T, index: number, array: T[]) => U): U[]
      
      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[]
      
      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
      
      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
      
      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
      
      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
      
      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[]
      
      toArray(): T[]
    
参数

没有参数。

返回值

T[]

toString(): string
      
      toString(): string
    
参数

没有参数。

返回值

string

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)[]): void
      
      reset(resultsTree: (any[] | T)[]): void
    
参数
resultsTree (any[] | T)[]

The query results to store

返回值

void

Triggers a change event by emitting on the changes EventEmitter.

notifyOnChanges(): void
      
      notifyOnChanges(): void
    
参数

没有参数。

返回值

void

internal

setDirty()
      
      setDirty()
    
参数

没有参数。

internal

destroy(): void
      
      destroy(): void
    
参数

没有参数。

返回值

void

使用说明

例子

Example

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