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


TypeScript ReflectiveInjector.resolve方法代码示例

本文整理汇总了TypeScript中angular2/core.ReflectiveInjector.resolve方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ReflectiveInjector.resolve方法的具体用法?TypeScript ReflectiveInjector.resolve怎么用?TypeScript ReflectiveInjector.resolve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在angular2/core.ReflectiveInjector的用法示例。


在下文中一共展示了ReflectiveInjector.resolve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createBindings

function createBindings(config: OneButtonPresetData): ResolvedReflectiveBinding[] {
    config.buttons = [
        {
            cssClass: config.okBtnClass,
            caption: config.okBtn,
            onClick: (modalComponent: MessageModal, $event?: MouseEvent) =>
                modalComponent.dialog.close(true)
        }
    ];

    return ReflectiveInjector.resolve([
        provide(MessageModalContext, {useValue: config})
    ]);
}
开发者ID:admirkb,项目名称:angular2-modal,代码行数:14,代码来源:OneButtonPreset.ts

示例2: main

export function main() {
  BrowserDomAdapter.makeCurrent();
  var iterations = getIntParameter('iterations');

  // This benchmark does not use bootstrap and needs to create a reflector
  setupReflector();
  var bindings = [A, B, C, D, E];
  var injector = ReflectiveInjector.resolveAndCreate(bindings);

  var D_KEY = ReflectiveKey.get(D);
  var E_KEY = ReflectiveKey.get(E);
  var childInjector = injector.resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([])
                          .resolveAndCreateChild([]);

  var variousProviders = [A, provide(B, {useClass: C}), [D, [E]], provide(F, {useValue: 6})];

  var variousProvidersResolved = ReflectiveInjector.resolve(variousProviders);

  function getByToken() {
    for (var i = 0; i < iterations; ++i) {
      injector.get(D);
      injector.get(E);
    }
  }
  function getByKey() {
    for (var i = 0; i < iterations; ++i) {
      injector.get(D_KEY);
      injector.get(E_KEY);
    }
  }

  function getChild() {
    for (var i = 0; i < iterations; ++i) {
      childInjector.get(D);
      childInjector.get(E);
    }
  }

  function instantiate() {
    for (var i = 0; i < iterations; ++i) {
      var child = injector.resolveAndCreateChild([E]);
      child.get(E);
    }
  }

  /**
   * Creates an injector with a variety of provider types.
   */
  function createVariety() {
    for (var i = 0; i < iterations; ++i) {
      ReflectiveInjector.resolveAndCreate(variousProviders);
    }
  }

  /**
   * Same as [createVariety] but resolves providers ahead of time.
   */
  function createVarietyResolved() {
    for (var i = 0; i < iterations; ++i) {
      ReflectiveInjector.fromResolvedProviders(variousProvidersResolved);
    }
  }

  bindAction('#getByToken', () => microBenchmark('injectAvg', iterations, getByToken));
  bindAction('#getByKey', () => microBenchmark('injectAvg', iterations, getByKey));
  bindAction('#getChild', () => microBenchmark('injectAvg', iterations, getChild));
  bindAction('#instantiate', () => microBenchmark('injectAvg', iterations, instantiate));
  bindAction('#createVariety', () => microBenchmark('injectAvg', iterations, createVariety));
  bindAction('#createVarietyResolved',
             () => microBenchmark('injectAvg', iterations, createVarietyResolved));
}
开发者ID:844496869,项目名称:angular,代码行数:74,代码来源:di_benchmark.ts

示例3: provide

import {ReflectiveInjector, provide} from 'angular2/core';
import {DashboardComponent} from './dashboard/dashboard.cmp';
import {LoginComponent} from './common/components/login.cmp';
import {TaskListComponent} from './task-list/task-list.cmp';
import {NotFoundComponent} from './common/components/notFound.cmp';
import {IConfig} from './common/services/FAR.d';
import {APP_CONFIG, CONFIG} from './common/services/app.config';

var injectors = ReflectiveInjector.resolve([
  provide(APP_CONFIG, {useValue: CONFIG})
]);

var config: IConfig = injectors[0].resolvedFactories[0].factory();
var ROUTE_NAME = config.routeName;

export const ROOT_ROUTES = [
  {
    path: '/', name: ROUTE_NAME.root, redirectTo: [ROUTE_NAME.login], useAsDefault: true,
    data: { title: '', requireAuth: false }
  },
  {
    path: '/login', name: ROUTE_NAME.login, component: LoginComponent,
    data: {
      title: 'FOO',
      requireAuth: false
    }
  },
  {
    path: '/dashboard', name: ROUTE_NAME.dashboard, component: DashboardComponent,
    data: {
      title: 'FOO',
开发者ID:AdamFaron,项目名称:FOO,代码行数:31,代码来源:routes.ts


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