本文整理匯總了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
};
}
示例2: createAccessorProvider
public static createAccessorProvider(component:any):any {
return {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => component),
multi: true
};
}
示例3: ControlValueAccessorProviderFactory
export function ControlValueAccessorProviderFactory(type: Type<any>): Provider {
return {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => type),
multi: true
};
}
示例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);
}
}
示例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]," +
示例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) {
示例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({
示例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);
}
}
示例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