本文整理汇总了TypeScript中angular2/core.forwardRef函数的典型用法代码示例。如果您正苦于以下问题:TypeScript forwardRef函数的具体用法?TypeScript forwardRef怎么用?TypeScript forwardRef使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了forwardRef函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Provider
import {Directive, Provider, forwardRef} from 'angular2/core';
import {NG_VALIDATORS, Validator, Control} from 'angular2/common';
const EMAIL_VALIDATOR = new Provider(NG_VALIDATORS, {useExisting: forwardRef(() => EmailValidator), multi: true});
@Directive({
selector: '[my-email-validator]',
providers: [EMAIL_VALIDATOR]
})
export class EmailValidator implements Validator {
validate(c: Control): {[key: string]: any} {
var inputValue = c.value;
console.log('validating...', inputValue);
if(inputValue == null)
return null;
var dotAt = inputValue.lastIndexOf('.');
var atAt = inputValue.lastIndexOf('@');
var len = inputValue.length;
if(dotAt > 0 && atAt > 0 && len > 3) {
if(atAt < len - 3 && dotAt != len - 1 && atAt < dotAt)
return null;
}
return {'emailValidation': 'Email is invalid'};
}
}
示例2: CONST_EXPR
import {CONST_EXPR, NumberWrapper} from "angular2/src/facade/lang";
import {NG_VALIDATORS, Validator, Control, AbstractControl} from "angular2/common";
import {Input, Provider, Directive, forwardRef} from "angular2/core";
import {isNumber} from "../../core/util/util";
const PATTERN_VALIDATOR = CONST_EXPR(new Provider(NG_VALIDATORS, {
useExisting: forwardRef(() => MdPatternValidator),
multi: true
}));
@Directive({
selector: '[mdPattern]',
providers: [PATTERN_VALIDATOR]
})
export class MdPatternValidator implements Validator {
/**
* Returns a validator that checks to see if a string matches a given Regular Expression
*/
static inline(pattern: string): any {
return function validate(control: AbstractControl): {[key: string]: any} {
if (control.value === '' || new RegExp(pattern).test(control.value)) {
return null;
}
return {
mdPattern: true
};
}
}
@Input()
mdPattern: string;
示例3: CONST_EXPR
import { Directive, Renderer, ElementRef, HostListener, forwardRef, Provider } from "angular2/core";
import { NG_VALUE_ACCESSOR, DefaultValueAccessor } from 'angular2/common';
import { CONST_EXPR } from 'angular2/src/facade/lang';
const PROVIDER = CONST_EXPR(new Provider(
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => UppercaseDirective), multi: true}
));
@Directive({
selector: "input[uppercase]",
bindings: [PROVIDER]
})
export class UppercaseDirective extends DefaultValueAccessor {
constructor(_renderer: Renderer, _elementRef: ElementRef) {
super(_renderer, _elementRef);
}
@HostListener("blur")
blur() {
this.onTouched();
}
@HostListener("input", ["$event.target.value"])
input(value) {
this.onChange(value.toUpperCase());
}
}
示例4: it
it('should wrap and unwrap the reference', () => {
var ref = forwardRef(() => String);
expect(ref instanceof Type).toBe(true);
expect(resolveForwardRef(ref)).toBe(String);
});
示例5: CONST_EXPR
ďťżimport {Directive, Renderer, ElementRef, Self, forwardRef, Provider} from 'angular2/core';
import {NG_VALUE_ACCESSOR, DefaultValueAccessor } from 'angular2/common';
import {CONST_EXPR} from 'angular2/src/facade/lang';
const PROVIDER = CONST_EXPR(new Provider(
NG_VALUE_ACCESSOR, { useExisting: forwardRef(() => DateValueAccessor), multi: true }));
@Directive({
selector:
'input[date]',
host: { '(input)': 'input($event.target.value)', '(blur)': 'blur()' },
providers: [PROVIDER]
})
export class DateValueAccessor extends DefaultValueAccessor {
constructor(_renderer: Renderer, _elementRef: ElementRef) {
super(_renderer, _elementRef);
}
blur() {
this.onTouched();
}
input(value) {
// Write back to model
if (value) {
value = value.split(/\./);
value = value[2] + "-" + value[1] + "-" + value[0];
}