TypeScript @angular-core.Component类(方法)实例源码

下面列出了TypeScript @angular-core.Component 类(方法)源码代码实例,从而了解它的用法。

作者:lyndontavare    项目:storyboo   
const createComponentFromTemplate = (template: string): Function => {
  const componentClass = class DynamicComponent {};

  return Component({
    template: template,
  })(componentClass);
};

作者:abuda7e    项目:nativescript-fontawesom   
var IconComponent = (function () {
    function IconComponent() {
        this.vAlign = 'center';
        this.hAlign = 'center';
        this.fontSize = "16px";
    }
    Object.defineProperty(IconComponent.prototype, "charName", {
        get: function () {
            return String.fromCharCode(iconList_1.iconList[this.iconName]);
        },
        enumerable: true,
        configurable: true
    });
    __decorate([
        core_1.Input('name'), 
        __metadata('design:type', Number)
    ], IconComponent.prototype, "iconName", void 0);
    __decorate([
        core_1.Input('vertical-align'), 
        __metadata('design:type', Object)
    ], IconComponent.prototype, "vAlign", void 0);
    __decorate([
        core_1.Input('horizontal-align'), 
        __metadata('design:type', Object)
    ], IconComponent.prototype, "hAlign", void 0);
    IconComponent = __decorate([
        core_1.Component({
            selector: 'Icon',
            template: "<Label style=\"font-size:{{fontSize}};horizontal-align:{{hAlign}};vertical-align:{{vAlign}};font-family:fontawesome\" [text]=\"charName\" ></Label>"
        }), 
        __metadata('design:paramtypes', [])
    ], IconComponent);
    return IconComponent;
}());

作者:jmcclanaha    项目:dynamic-component-generato   
createComponentFactory(resolver: ComponentResolver, metadata: ComponentMetadata): Promise<ComponentFactory<any>> {
    // Define component to create
    const cmpClass =  class DynamicComponent {};

    // Define component and metadata(ie @Component())
    const decoratedCmp = Component(metadata)(cmpClass);

    // Return ComponentFactory to create components with
    return resolver.resolveComponent(decoratedCmp);
  }

作者:RandyBo    项目:new-route   
export function createComponentFactory(resolver: ComponentResolver, metadata: ComponentMetadata): Promise<ComponentFactory<any>> {
    const cmpClass = class DynamicComponentA {
        login(modelValue: any): Observable<boolean> | boolean {
            console.log("dynamicLoginComponent:" + JSON.stringify(modelValue));
            return false;
        }
    };
    const decoratedCmp = Component(metadata)(cmpClass);
    return resolver.resolveComponent(decoratedCmp);
}

作者:aluanhadda    项目:ng2-conventions-decorator   
return <T extends Manifest, Instance>(target: T & (new (...args: any[]) => {
    [P in keyof Instance]: Instance[P]
  })) => {
    ensureName(target);
    const componentOptions = (
      typeof styleOrOptions !== 'string' && styleOrOptions ||
      typeof styleOrOptions === 'string' && options || {}
    ) as ComponentOptions & {
      template: string, styles?: string[], selector: string
    };

    componentOptions.selector = kebabCase(target.name, 'Component');
    componentOptions.styles = typeof styleOrOptions === 'string' && [styleOrOptions] || undefined;
    componentOptions.template = template;
    return Component(componentOptions)(target);
  };

作者:tycho0    项目:react-storyboo   
// a component template for testing other components, by full html template
 test_comp_html(tmplt, cls, obs_pars = {}, static_pars = {}, outputs = {}) {
   let cmp = class {
     constructor() {
       for (let k in obs_pars) this[k] = new BehaviorSubject(obs_pars[k]);
       for (let k in static_pars) this[k] = static_pars[k];
       for (let k in outputs) this[k] = outputs[k];
     }
   };
   Reflect.decorate([Component({
     // selector: 'test',
     directives: [cls],
     template: tmplt,
   })], cmp);
   Reflect.decorate([ViewChild(cls)], cmp.prototype, 'comp');
   return cmp;
 }

作者:laco041    项目:angular2-common   
export function createDynamicComponent(resolver: ComponentResolver, metadata: ComponentMetadata, context: any = {}): Promise<ComponentFactory<any>> {
    const cmpClass = class dynamicComponent {
        constructor() {
            if ('dynamicOnInit' in this) {
                (this as any)['dynamicOnInit'](this);
            }
        }
    };
    (cmpClass.prototype as any)['dynamicOnInit'] = (self: any) => {
        Object.keys(context).forEach(key => {
            self[key] = context[key];
        });
    };
    const decoratedCmp = Component(metadata)(cmpClass);
    return resolver.resolveComponent(decoratedCmp as Type);
}

作者:formly-j    项目:ng2-forml   
export function MockComponent(options: Component): Component {
  const metadata: Component = {
    selector: options.selector,
    template: options.template || '',
    inputs: options.inputs,
    outputs: options.outputs || [],
    exportAs: options.exportAs || '',
  };

  class Mock {}

  metadata.outputs.forEach(method => {
    Mock.prototype[method] = new EventEmitter<any>();
  });

  return Component(metadata)(Mock as any);
}

作者:iamthelogik8    项目:fron   
export function MockComponent(options: Component, spies: string[] = []) {
  let metadata: Component = {
    selector: options.selector,
    template: options.template || '',
    inputs: options.inputs,
    outputs: options.outputs
  };
  let component = class _ {};
  if (options.outputs) {
    for (let output of options.outputs) {
      component.prototype[output] = new EventEmitter<any>();
    }
  }
  for (let spy of spies) {
    component.prototype[spy] = jasmine.createSpy(spy);
  }
  return Component(metadata)(component);
}

作者:brakmi    项目:Angular_VRDem   
export function createComponentFactory(compiler: Compiler,
                                       metadata: Component):
                                              Promise<ComponentFactory<any>> {
    const cmpClass = class DynamicComponent {};
    const decoratedCmp = Component(metadata)(cmpClass);

    @NgModule({ 
        imports: [ CommonModule ], 
        declarations: [decoratedCmp],
        schemas: [ CUSTOM_ELEMENTS_SCHEMA ] })
    class DynamicHtmlModule { }

    return compiler.compileModuleAndAllComponentsAsync(DynamicHtmlModule)
       .then((moduleWithComponentFactory: ModuleWithComponentFactories<any>) => 
                {
                    return moduleWithComponentFactory.componentFactories.find
                                ((x) => x.componentType === decoratedCmp);
                });
}


问题


面经


文章

微信
公众号

扫码关注公众号