當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。