当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript core.forwardRef函数代码示例

本文整理汇总了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'};
    }

}
开发者ID:tszpinda,项目名称:angular-2-forms,代码行数:31,代码来源:email.validator.ts

示例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;
开发者ID:790,项目名称:ng2-material,代码行数:31,代码来源:validators.ts

示例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());
    }
}
开发者ID:xenoxaos,项目名称:CloudShack,代码行数:27,代码来源:uppercase.directive.ts

示例4: it

 it('should wrap and unwrap the reference', () => {
   var ref = forwardRef(() => String);
   expect(ref instanceof Type).toBe(true);
   expect(resolveForwardRef(ref)).toBe(String);
 });
开发者ID:TedSander,项目名称:angular,代码行数:5,代码来源:forward_ref_spec.ts

示例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];
        }
开发者ID:manfredsteyer,项目名称:forms-sample-jm-2016-03,代码行数:31,代码来源:date-value-accessor.ts


注:本文中的angular2/core.forwardRef函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。