當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript di.bind函數代碼示例

本文整理匯總了TypeScript中angular2/di.bind函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript bind函數的具體用法?TypeScript bind怎麽用?TypeScript bind使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了bind函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: inject

 inject([AsyncTestCompleter], (async) => {
   bootstrap(HierarchyAppCmp, [testBindings, bind(appBaseHrefToken).toValue('/my/app')])
       .then((applicationRef) => {
         var router = applicationRef.hostComponent.router;
         router.subscribe((_) => {
           expect(el).toHaveText('root { parent { hello } }');
           expect(applicationRef.hostComponent.location.path())
               .toEqual('/my/app/parent/child');
           async.done();
         });
         router.navigate('/parent/child');
       });
 }));
開發者ID:Salim-K,項目名稱:angular,代碼行數:13,代碼來源:router_integration_spec.ts

示例2: _getAppBindings

function _getAppBindings() {
  var appDoc;
  try {
    appDoc = DOM.defaultDoc();
  } catch (e) {
    appDoc = null;
  }
  return [bind(appDocumentToken).toValue(appDoc), bind(ShadowDomStrategy).toFactory((styleUrlResolver, doc) => new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, doc.head), [StyleUrlResolver, appDocumentToken]), Compiler, CompilerCache, bind(TemplateResolver).toClass(MockTemplateResolver), bind(ChangeDetection).toValue(dynamicChangeDetection), TemplateLoader, DirectiveMetadataReader, Parser, Lexer, ExceptionHandler, bind(XHR).toClass(MockXHR), ComponentUrlMapper, UrlResolver, StyleUrlResolver, StyleInliner, TestBed, bind(VmTurnZone).toClass(MockVmTurnZone), bind(EventManager).toFactory((zone) => {
    var plugins = [new DomEventsPlugin()];
    return new EventManager(plugins, zone);
  }, [VmTurnZone])];
}
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:12,代碼來源:test_injector.ts

示例3: bindTo

 static bindTo(childTokens): List<Binding> {
   return [
     bind(_CHILDREN)
         .toAsyncFactory((injector) => PromiseWrapper.all(
                             ListWrapper.map(childTokens, (token) => injector.asyncGet(token))),
                         [Injector]),
     bind(WebDriverExtension)
         .toFactory(
             (children, capabilities) => {
               var delegate;
               ListWrapper.forEach(children, (extension) => {
                 if (extension.supports(capabilities)) {
                   delegate = extension;
                 }
               });
               if (isBlank(delegate)) {
                 throw new BaseException('Could not find a delegate for given capabilities!');
               }
               return delegate;
             },
             [_CHILDREN, Options.CAPABILITIES])
   ];
 }
開發者ID:AsherBarak,項目名稱:angular,代碼行數:23,代碼來源:web_driver_extension.ts

示例4: beforeEach

 beforeEach(() => {
   injector = Injector.resolveAndCreate([
     BaseRequestOptions,
     MockBackend,
     bind(Http).toFactory(
         function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
           return new Http(backend, defaultOptions);
         },
         [MockBackend, BaseRequestOptions])
   ]);
   http = injector.get(Http);
   backend = injector.get(MockBackend);
   baseResponse = new Response(new ResponseOptions({body: 'base response'}));
 });
開發者ID:cedriclam,項目名稱:angular,代碼行數:14,代碼來源:http_spec.ts

示例5: jsmFn

 jsmFn(name, function(done) {
   var async = false;
   var completerBinding = bind(AsyncTestCompleter).toFactory(() => {
     if (!inIt)
       throw new Error('AsyncTestCompleter can only be injected in an "it()"');
     async = true;
     return new AsyncTestCompleter(done);
   });
   var injector = createTestInjector([...testBindings, completerBinding]);
   runner.run(injector);
   if (!(fn instanceof FunctionWithParamTokens)) {
     fn = inject([], fn);
   }
   inIt = true;
   fn.execute(injector);
   inIt = false;
   if (!async)
     done();
 });
開發者ID:gdi2290,項目名稱:sample-Angular2,代碼行數:19,代碼來源:test_lib.ts

示例6: _getAppBindings

/**
 * Returns the application injector bindings.
 *
 * This must be kept in sync with _injectorBindings() in application.js
 *
 * @returns {any[]}
 */
function _getAppBindings() {
  var appDoc;

  // The document is only available in browser environment
  try {
    appDoc = DOM.defaultDoc();
  } catch (e) {
    appDoc = null;
  }
  return [
    bind(DOCUMENT_TOKEN)
        .toValue(appDoc),
    bind(ShadowDomStrategy)
        .toFactory((styleUrlResolver, doc) =>
                           new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, doc.head),
                   [StyleUrlResolver, DOCUMENT_TOKEN]),
    DomRenderer,
    DefaultDomCompiler,
    bind(Renderer).toAlias(DomRenderer),
    bind(RenderCompiler).toAlias(DefaultDomCompiler),
    ProtoViewFactory,
    AppViewPool,
    AppViewManager,
    AppViewManagerUtils,
    ELEMENT_PROBE_CONFIG,
    bind(APP_VIEW_POOL_CAPACITY).toValue(500),
    Compiler,
    CompilerCache,
    bind(TemplateResolver).toClass(MockTemplateResolver),
    bind(PipeRegistry).toValue(defaultPipeRegistry),
    bind(ChangeDetection).toClass(DynamicChangeDetection),
    TemplateLoader,
    DynamicComponentLoader,
    DirectiveResolver,
    Parser,
    Lexer,
    ExceptionHandler,
    bind(XHR).toClass(MockXHR),
    ComponentUrlMapper,
    UrlResolver,
    StyleUrlResolver,
    StyleInliner,
    TestBed,
    TestComponentBuilder,
    bind(NgZone).toClass(MockNgZone),
    bind(EventManager)
        .toFactory(
            (zone) => {
              var plugins = [
                new DomEventsPlugin(),
              ];
              return new EventManager(plugins, zone);
            },
            [NgZone]),
  ];
}
開發者ID:Mariem-07,項目名稱:angular,代碼行數:63,代碼來源:test_injector.ts

示例7: bind

 * #Example
 *
 * ```
 * import {HTTP_BINDINGS, Http} from 'http/http';
 * @Component({selector: 'http-app', viewBindings: [HTTP_BINDINGS]})
 * @View({template: '{{data}}'})
 * class MyApp {
 *   constructor(http:Http) {
 *     http.request('data.txt').subscribe(res => this.data = res.text());
 *   }
 * }
 * ```
 *
 */
export const HTTP_BINDINGS: List<any> = [
  bind(ConnectionBackend)
      .toClass(XHRBackend),
  BrowserXhr,
  bind(RequestOptions).toClass(BaseRequestOptions),
  bind(ResponseOptions).toClass(BaseResponseOptions),
  Http
];

export const JSONP_BINDINGS: List<any> = [
  bind(ConnectionBackend)
      .toClass(JSONPBackend),
  BrowserJsonp,
  bind(RequestOptions).toClass(BaseRequestOptions),
  bind(ResponseOptions).toClass(BaseResponseOptions),
  Jsonp
];
開發者ID:synaptek,項目名稱:angular,代碼行數:31,代碼來源:http.ts

示例8: hasNativeShadowDom

import {
  ShadowDomStrategy,
  NativeShadowDomStrategy,
  EmulatedScopedShadowDomStrategy,
  EmulatedUnscopedShadowDomStrategy
} from 'angular2/render';
import {bind} from 'angular2/di';
import {document} from 'angular2/src/facade/browser';
import {DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer';

export function hasNativeShadowDom() {
  return Boolean(document && document.body && document.body.createShadowRoot);
}

export var emulatedScopedShadowDomInjectables = [
  bind(ShadowDomStrategy).toFactory((doc) => {
    return new EmulatedScopedShadowDomStrategy(doc.body);
  }, [DOCUMENT_TOKEN])
];

// use EmulatedScope if Native is not supported
export var nativeShadowDomInjectables = hasNativeShadowDom() ? [
    bind(ShadowDomStrategy).toClass(NativeShadowDomStrategy)
  ] : emulatedScopedShadowDomInjectables;

export var emulatedUnscopedShadowDomInjectables = [
  bind(ShadowDomStrategy).toFactory((doc) => {
    return new EmulatedUnscopedShadowDomStrategy(doc.body);
  }, [DOCUMENT_TOKEN])
];
開發者ID:SekibOmazic,項目名稱:angular2-rx,代碼行數:30,代碼來源:shadowDomInjectables.ts

示例9: _injectorBindings

import {AppViewPool, APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils';
import {AppViewListener} from 'angular2/src/core/compiler/view_listener';
import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory';
import {Renderer, RenderCompiler} from 'angular2/src/render/api';
import {DomRenderer, DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer';
import {DefaultDomCompiler} from 'angular2/src/render/dom/compiler/compiler';
import {internalView} from 'angular2/src/core/compiler/view_ref';

import {appComponentRefToken, appComponentTypeToken} from './application_tokens';

var _rootInjector: Injector;

// Contains everything that is safe to share between applications.
var _rootBindings = [bind(Reflector).toValue(reflector), TestabilityRegistry];

function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
  var bestChangeDetection: Type = DynamicChangeDetection;
  if (PreGeneratedChangeDetection.isSupported()) {
    bestChangeDetection = PreGeneratedChangeDetection;
  } else if (JitChangeDetection.isSupported()) {
    bestChangeDetection = JitChangeDetection;
  }
  return [
    bind(DOCUMENT_TOKEN)
        .toValue(DOM.defaultDoc()),
    bind(appComponentTypeToken).toValue(appComponentType),
    bind(appComponentRefToken)
        .toFactory(
            (dynamicComponentLoader, injector, testability, registry) => {
開發者ID:cedriclam,項目名稱:angular,代碼行數:31,代碼來源:application.ts

示例10: Boolean

/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../custom_typings/ng2.d.ts" />
import {ShadowDomStrategy, NativeShadowDomStrategy} from 'angular2/core';
import {StyleUrlResolver} from 'angular2/src/render/dom/shadow_dom/style_url_resolver';
import {bind} from 'angular2/di';
import {document} from 'angular2/src/facade/browser';

export var hasShadowDom = Boolean(document && document.body && document.body.createShadowRoot);

export var shadowDomInjectables = [
  (!hasShadowDom) ? [] :
  bind(ShadowDomStrategy).toFactory(
    styleUrlResolver => new NativeShadowDomStrategy(styleUrlResolver),
    [StyleUrlResolver]
  )
]
開發者ID:StanShumsky,項目名稱:angular2-webpack-starter,代碼行數:16,代碼來源:checkIfShadowDom.ts


注:本文中的angular2/di.bind函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。