本文整理匯總了TypeScript中@angular/core.bind函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript bind函數的具體用法?TypeScript bind怎麽用?TypeScript bind使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了bind函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: sample
sample({id, execute, prepare, microMetrics, providers}:
{id: string, execute?: any, prepare?: any, microMetrics?: any, providers?: any}):
Promise<SampleState> {
var sampleProviders = [
_DEFAULT_PROVIDERS,
this._defaultProviders,
bind(Options.SAMPLE_ID).toValue(id),
bind(Options.EXECUTE).toValue(execute)
];
if (isPresent(prepare)) {
sampleProviders.push(bind(Options.PREPARE).toValue(prepare));
}
if (isPresent(microMetrics)) {
sampleProviders.push(bind(Options.MICRO_METRICS).toValue(microMetrics));
}
if (isPresent(providers)) {
sampleProviders.push(providers);
}
var inj = ReflectiveInjector.resolveAndCreate(sampleProviders);
var adapter = inj.get(WebDriverAdapter);
return PromiseWrapper
.all([adapter.capabilities(), adapter.executeScript('return window.navigator.userAgent;')])
.then((args) => {
var capabilities = args[0];
var userAgent = args[1];
// This might still create instances twice. We are creating a new injector with all the
// providers.
// Only WebDriverAdapter is reused.
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
// injectors are handled better.
var injector = ReflectiveInjector.resolveAndCreate([
sampleProviders,
bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {useValue: adapter})
]);
var sampler = injector.get(Sampler);
return sampler.sample();
});
}
示例2: bind
.then((args) => {
var capabilities = args[0];
var userAgent = args[1];
// This might still create instances twice. We are creating a new injector with all the
// providers.
// Only WebDriverAdapter is reused.
// TODO vsavkin consider changing it when toAsyncFactory is added back or when child
// injectors are handled better.
var injector = ReflectiveInjector.resolveAndCreate([
sampleProviders,
bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {useValue: adapter})
]);
var sampler = injector.get(Sampler);
return sampler.sample();
});
示例3: main
export function main(initialHmrState?: any): Promise<any> {
return bootstrap(App, [
// To add more vendor providers please look in the platform/ folder
...PLATFORM_PROVIDERS,
...ENV_PROVIDERS,
...APP_PROVIDERS,
...HTTP_PROVIDERS,
bind(LocationStrategy).toClass(PathLocationStrategy)
])
.then(decorateComponentRef)
.catch(err => console.error(err));
}
示例4: bootstrap
import { PatientStore } from './components/state/PatientStore';
import { TreatmentBackendService } from './services/TreatmentBackendService';
import { TreatmentStore } from './components/state/TreatmentStore';
import { UiStateStore } from './components/state/UiStateStore';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
// ROUTER_BINDINGS,
PatientStore,
TreatmentStore,
UiStateStore,
FORM_PROVIDERS,
HTTP_PROVIDERS,
ELEMENT_PROBE_PROVIDERS,
MATERIAL_PROVIDERS,
NotificationService,
// PatientService,
PatientBackendService,
TreatmentBackendService,
provide(AuthHttp, {
useFactory: (http) => {
return new AuthHttp(new AuthConfig(), http);
},
deps: [Http]
}),
provide(APP_BASE_HREF, {useValue : '/' }),
bind(LocationStrategy).toClass(PathLocationStrategy)
]).then(
success => console.log('AppComponent bootstrapped!'),
error => console.log('AppComponent NOT bootstrapped!', error)
);
示例5: bootstrap
import {bootstrap} from '@angular/platform-browser-dynamic';
import {HTTP_PROVIDERS} from '@angular/http';
import 'rxjs/Rx';
import{ComponentOne} from './component_one';
import{ComponentTwo} from './component_two';
import{CountriesList} from './app.component';
@Component({
selector: 'my-app',
template: `
<h1>Component Router</h1>
<nav>
<a [routerLink]="['ComponentOne']">Component One</a><hr/>
<a [routerLink]="['ComponentTwo']">Component Two</a><hr/>
<a [routerLink]="['CountriesList']">List of countries</a>
</nav>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{path:'/component-one', name: 'ComponentOne', component: ComponentOne},
{path:'/component-two', name: 'ComponentTwo', component: ComponentTwo},
{path:'/countries', name: 'CountriesList', component:CountriesList}
])
export class AppComponent { }
bootstrap(AppComponent, [HTTP_PROVIDERS,
ROUTER_PROVIDERS,bind(APP_BASE_HREF).toValue(location.pathname)
]);
示例6: enableProdMode
import { enableProdMode } from '@angular/core';
import {bind, provide} from '@angular/core';
import { LocationStrategy, HashLocationStrategy} from '@angular/common';
import {AppComponent, environment} from './app';
import {provideForms, disableDeprecatedForms} from '@angular/forms';
import {APP_ROUTER_PROVIDER, AuthGuard} from './app';
import {DataService} from './app/shared';
import {HTTP_PROVIDERS, Http} from '@angular/http';
import {AuthHttp, AuthConfig} from 'angular2-jwt';
import { bootstrap } from '@angular/platform-browser-dynamic';
if (environment.production) {
enableProdMode();
}
bootstrap(AppComponent, [
disableDeprecatedForms(),
provideForms(),
HTTP_PROVIDERS,
APP_ROUTER_PROVIDER,
bind(LocationStrategy).toClass(HashLocationStrategy),
provide(AuthConfig, { useFactory: () => {
return new AuthConfig();
}}),
AuthHttp,
AuthGuard,
DataService
]);
示例7: bootstrap
import { enableProdMode } from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { ROUTER_PROVIDERS} from'@angular/router';
import { AppComponent } from './app.component';
import {bind} from '@angular/core';
import {LocationStrategy, HashLocationStrategy} from '@angular/common';
import { SpinnerService } from './shared/spinner.service';
// enableProdMode();
bootstrap(AppComponent,[ROUTER_PROVIDERS,bind(LocationStrategy).toClass(HashLocationStrategy),SpinnerService])
.then(success => console.log(`Bootstrap success`))
.catch(error => console.log(error));
示例8: bootstrap
import {bootstrap} from '@angular/platform-browser-dynamic';
import {AppComponent} from './components/app/app.component'
import {LocationStrategy, HashLocationStrategy} from '@angular/common'
import {bind} from '@angular/core'
bootstrap(AppComponent, [bind(LocationStrategy).toClass(HashLocationStrategy)])
.then(success => console.log(`Bootstrap success `))
.catch(error => console.log(error));
示例9: transform
import {Pipe, bind} from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'fromNow'
})
export class FromNowPipe {
transform(value: any, args: Array<any>): string {
return moment(value).fromNow();
}
}
export var fromNowPipeInjectables: Array<any> = [
bind(FromNowPipe).toValue(FromNowPipe)
];
示例10: constructor
import { Component, Injectable, bind } from '@angular/core';
import { ImageItem, ImageItemComponent } from './image_item';
import {Observable} from 'rxjs/Rx';
import 'rxjs/Rx';
import {
Http,
Response,
RequestOptions,
Headers
} from '@angular/http';
@Injectable()
export class ImageService {
public images: Observable<any>;
constructor(public http: Http ) {
}
refreshImages(): any
{
this.images = this.http.get('http://localhost:8020/get_all_images')
.map((res:Response) => { return res;})
.publishReplay(1).refCount();
return this.images;
}
}
export var imageServiceInjectables: Array<any> = [
bind(ImageService).toClass(ImageService)
];