當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.forwardRef函數代碼示例

本文整理匯總了TypeScript中@angular/core.forwardRef函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript forwardRef函數的具體用法?TypeScript forwardRef怎麽用?TypeScript forwardRef使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了forwardRef函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: ValidatorProviderFactory

export function ValidatorProviderFactory(type: Type<any>): Provider {
    return {
        provide: NG_VALIDATORS,
        useExisting: forwardRef(() => type),
        multi: true
    };
}
開發者ID:Nimzi-Git,項目名稱:angular-io-datepicker,代碼行數:7,代碼來源:common.ts

示例2: createAccessorProvider

 public static createAccessorProvider(component:any):any {
     return {
         provide: NG_VALUE_ACCESSOR,
         useExisting: forwardRef(() => component),
         multi: true
     };
 }
開發者ID:hguerrerojaime,項目名稱:bong2,代碼行數:7,代碼來源:provider.utils.ts

示例3: ControlValueAccessorProviderFactory

export function ControlValueAccessorProviderFactory(type: Type<any>): Provider {
    return {
        provide: NG_VALUE_ACCESSOR,
        useExisting: forwardRef(() => type),
        multi: true
    };
}
開發者ID:Nimzi-Git,項目名稱:angular-io-datepicker,代碼行數:7,代碼來源:common.ts

示例4: forwardRef

import { Directive, forwardRef } from '@angular/core';
import { NG_VALIDATORS, Validator, AbstractControl } from '@angular/forms';

import { url } from './';

const URL_VALIDATOR: any = {
  provide: NG_VALIDATORS,
  useExisting: forwardRef(() => UrlValidator),
  multi: true
};

@Directive({
  selector: '[url][formControlName],[url][formControl],[url][ngModel]',
  providers: [URL_VALIDATOR]
})
export class UrlValidator implements Validator {
  validate(c: AbstractControl): {[key: string]: any} {
    return url(c);
  }
}
開發者ID:diandsonc,項目名稱:ng2-validation,代碼行數:20,代碼來源:directive.ts

示例5: forwardRef

import { Directive, ElementRef, forwardRef } from "@angular/core";
import { NG_VALUE_ACCESSOR } from "@angular/forms";
import { BaseValueAccessor } from "./base-value-accessor";
import { View } from "tns-core-modules/ui/core/view";

const TEXT_VALUE_ACCESSOR = {
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => TextValueAccessor),
    multi: true,
};

export type TextView = {text: string} & View;

/**
 * The accessor for writing a text and listening to changes that is used by the
 * {@link NgModel} directives.
 *
 *  ### Example
 *  ```
 *  <TextField [(ngModel)]="model.test">
 *  ```
 */
@Directive({
    selector:
        "TextField[ngModel],TextField[formControlName],TextField[formControl]," +
        "textField[ngModel],textField[formControlName],textField[formControl]," +
        "textfield[ngModel],textfield[formControlName],textfield[formControl]," +
        "text-field[ngModel],text-field[formControlName],text-field[formControl]," +

        "TextView[ngModel],TextView[formControlName],TextView[formControl]," +
        "textView[ngModel],textView[formControlName],textView[formControl]," +
開發者ID:NathanWalker,項目名稱:nativescript-angular,代碼行數:31,代碼來源:text-value-accessor.ts

示例6: forwardRef

import { Directive, ElementRef, forwardRef } from "@angular/core";
import { NG_VALUE_ACCESSOR } from "@angular/forms";
import { BaseValueAccessor } from "./base-value-accessor";
import { Slider } from "tns-core-modules/ui/slider";

const NUMBER_VALUE_ACCESSOR = {
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => NumberValueAccessor),
    multi: true,
};

/**
 * The accessor for setting a value and listening to changes that is used by the
 * {@link NgModel}
 *
 *  ### Example
 *  ```
 *  <Slider [(ngModel)]="model.test">
 *  ```
 */
@Directive({
    selector:
        "Slider[ngModel],Slider[formControlName],Slider[formControl]," +
        "slider[ngModel],slider[formControlName],slider[formControl]",
    providers: [NUMBER_VALUE_ACCESSOR],
    host: {
        "(valueChange)": "onChange($event.value)",
    },
})
export class NumberValueAccessor extends BaseValueAccessor<Slider> { // tslint:disable-line:directive-class-suffix
    constructor(elementRef: ElementRef) {
開發者ID:NathanWalker,項目名稱:nativescript-angular,代碼行數:31,代碼來源:number-value-accessor.ts

示例7: expect

                 .then((compFixture) => {
                   let nestedChildCompEl = compFixture.debugElement.children[0].children[0];
                   let nestedChildComp: NestedChildComp = nestedChildCompEl.componentInstance;
                   expect(nestedChildComp.cfr.resolveComponentFactory(ChildComp).componentType)
                       .toBe(ChildComp);
                   expect(() => nestedChildComp.cfr.resolveComponentFactory(NestedChildComp))
                       .toThrow(new NoComponentFactoryError(NestedChildComp));
                   async.done();
                 });
           }));

  });
}

var DIRECTIVES: any[] = [
  forwardRef(() => NestedChildComp),
  forwardRef(() => ChildComp),
  forwardRef(() => MainComp),
];

@Component({selector: 'nested', directives: DIRECTIVES, template: ''})
class NestedChildComp {
  constructor(public cfr: ComponentFactoryResolver) {}
}

@Component({selector: 'child', precompile: [NestedChildComp], directives: DIRECTIVES, template: ''})
class ChildComp {
  constructor(public cfr: ComponentFactoryResolver) {}
}

@Component({
開發者ID:HongXG,項目名稱:angular,代碼行數:31,代碼來源:precompile_integration_spec.ts

示例8: forwardRef

import { Directive, Input, forwardRef, OnInit } from '@angular/core';
import { NG_VALIDATORS, Validator, ValidatorFn, AbstractControl } from '@angular/forms';

import { CustomValidators } from '../';

const EQUAL_TO_VALIDATOR: any = {
    provide: NG_VALIDATORS,
    useExisting: forwardRef(() => EqualToValidator),
    multi: true
};

@Directive({
    selector: '[equalTo][formControlName],[equalTo][formControl],[equalTo][ngModel]',
    providers: [EQUAL_TO_VALIDATOR]
})
export class EqualToValidator implements Validator, OnInit {
    @Input() equalTo: AbstractControl;

    private validator: ValidatorFn;

    ngOnInit() {
        this.validator = CustomValidators.equalTo(this.equalTo);
    }

    validate(c: AbstractControl): {[key: string]: any} {
        return this.validator(c);
    }
}
開發者ID:Cloudhubke,項目名稱:ng2-validation,代碼行數:28,代碼來源:equal-to.ts

示例9: validate

 *
 * @stable
 */
export interface Validator {
  validate(c: AbstractControl): ValidationErrors|null;
  registerOnValidatorChange?(fn: () => void): void;
}

/** @experimental */
export interface AsyncValidator extends Validator {
  validate(c: AbstractControl): Promise<ValidationErrors|null>|Observable<ValidationErrors|null>;
}

export const REQUIRED_VALIDATOR: Provider = {
  provide: NG_VALIDATORS,
  useExisting: forwardRef(() => RequiredValidator),
  multi: true
};

export const CHECKBOX_REQUIRED_VALIDATOR: Provider = {
  provide: NG_VALIDATORS,
  useExisting: forwardRef(() => CheckboxRequiredValidator),
  multi: true
};


/**
 * A Directive that adds the `required` validator to any controls marked with the
 * `required` attribute, via the {@link NG_VALIDATORS} binding.
 *
 * ### Example
開發者ID:diestrin,項目名稱:angular,代碼行數:31,代碼來源:validators.ts


注:本文中的@angular/core.forwardRef函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。