本文整理匯總了TypeScript中@angular/core.provide函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript provide函數的具體用法?TypeScript provide怎麽用?TypeScript provide使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了provide函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: provide
import {provide} from '@angular/core';
import {t} from '../../test.framework/index';
import {CoreConfigService, ConsoleService, LogService} from '../index';
const providers: any[] = [
provide(ConsoleService, { useValue: console }),
LogService
];
export function main() {
t.describe('core.framework: LogService', () => {
t.be(() => {
// ensure statics are in default state
CoreConfigService.RESET();
// spy
t.spyOn(console, 'log');
t.spyOn(console, 'error');
t.spyOn(console, 'warn');
t.spyOn(console, 'info');
});
t.describe('api', () => {
t.bep(() => providers);
t.it('sanity', t.inject([LogService], (log: LogService) => {
t.e(log.debug).toBeDefined();
t.e(log.error).toBeDefined();
t.e(log.warn).toBeDefined();
示例2: enableProdMode
import {bootstrap} from '@angular/platform-browser-dynamic';
import {provide, enableProdMode} from '@angular/core';
import {HTTP_PROVIDERS, Http } from '@angular/http';
import {APP_ROUTER_PROVIDERS} from './app.routes';
import {AppComponent} from './app.component';
import {AuthHttp, AuthConfig, tokenNotExpired, JwtHelper} from 'angular2-jwt/angular2-jwt';
import {TRANSLATE_PROVIDERS, TranslateService, TranslatePipe, TranslateLoader, TranslateStaticLoader} from 'ng2-translate/ng2-translate';
import 'rxjs/add/operator/map';
enableProdMode();
declare var toast: any;
bootstrap(AppComponent, [
APP_ROUTER_PROVIDERS,
HTTP_PROVIDERS,
TRANSLATE_PROVIDERS,
provide(AuthConfig, {useValue: new AuthConfig({
headerName: 'X-AUTH'
})}),
provide(AuthHttp, {
useFactory: (http) => {
return new AuthHttp(new AuthConfig({
headerName: 'X-AUTH'
}), http);
},
deps: [Http]
}),
AuthHttp
]);
示例3: bootstrap
// Imports for loading & configuring the in-memory web api
import { provide } from '@angular/core';
import { XHRBackend } from '@angular/http';
// use in memory to fake the server
import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
import { InMemoryDataService } from './in-memory-data.service';
// the usual stuff for bootstraping
import {bootstrap} from '@angular/platform-browser-dynamic';
import { HTTP_PROVIDERS } from '@angular/http';
import {AppComponent} from './app.component';
bootstrap(AppComponent, [
HTTP_PROVIDERS,
provide(XHRBackend, { useClass: InMemoryBackendService }), // in-mem server
provide(SEED_DATA, { useClass: InMemoryDataService }) // in-mem server data
]);
示例4: enableProdMode
// Imports for loading & configuring the in-memory web api
import { XHRBackend } from '@angular/http';
import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
import { Locker, LockerConfig } from 'angular2-locker'
// The usual bootstrapping imports
import { bootstrap } from '@angular/platform-browser-dynamic';
import { HTTP_PROVIDERS } from '@angular/http';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import { enableProdMode, provide } from '@angular/core';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';
import { AppComponent } from './components/app.component';
import { appRouterProviders } from './app.routes';
enableProdMode();
bootstrap(AppComponent, [
disableDeprecatedForms(),
provideForms(),
appRouterProviders,
HTTP_PROVIDERS,
{ provide: LocationStrategy, useClass: HashLocationStrategy },
provide(LockerConfig, {
useValue: new LockerConfig('superheroApp', Locker.DRIVERS.LOCAL)
}),
Locker
]);
示例5: provide
// libs
import {Angulartics2} from 'angulartics2';
import {Angulartics2Segment} from 'angulartics2/src/providers/angulartics2-segment';
import {provideStore} from '@ngrx/store';
import {TranslateService} from 'ng2-translate/ng2-translate';
// app
import {ConsoleService, LogService} from '../core.framework/index';
import {AnalyticsService} from '../analytics.framework/index';
import {AppConfigService, nameListReducer} from '../app.framework/index';
import {MultilingualService, multilingualReducer} from '../i18n.framework/index';
import {NSAngulartics2Segment} from './services/ns-angulartics2-segment.service';
import {NSLogService} from './services/ns-log.service';
// custom i18n language support
MultilingualService.SUPPORTED_LANGUAGES = AppConfigService.SUPPORTED_LANGUAGES;
export const NS_APP_PROVIDERS: any[] = [
HTTP_PROVIDERS,
provide(ConsoleService, { useValue: console }),
provide(LogService, { useClass: NSLogService }),
provideStore({
i18n: multilingualReducer,
names: nameListReducer
}),
Angulartics2,
provide(Angulartics2Segment, { useClass: NSAngulartics2Segment }),
AnalyticsService,
TranslateService,
MultilingualService
];
示例6: enableProdMode
ďťż
/// <reference path="../typings/main.d.ts" />
import { bootstrap } from '@angular/platform-browser-dynamic';
import {HashLocationStrategy, APP_BASE_HREF, LocationStrategy} from '@angular/common';
import {ROUTER_PROVIDERS} from '@angular/router-deprecated';
import {bind, provide, enableProdMode} from '@angular/core';
import {HTTP_PROVIDERS} from '@angular/http';
import {AppComponent} from './shared/app.component';
import "rxjs/Rx";
//import {MATERIAL_PROVIDERS} from "ng2-material";
enableProdMode();
bootstrap(AppComponent, [ROUTER_PROVIDERS, bind(LocationStrategy).toClass(HashLocationStrategy), HTTP_PROVIDERS, provide(APP_BASE_HREF, { useValue: '/' })]);
示例7: bootstrap
/// <reference path="../typings/browser/ambient/es6-shim/index.d.ts" />
import {bootstrap} from '@angular/platform-browser-dynamic';
import {bind, provide} from '@angular/core';
import { LocationStrategy, HashLocationStrategy} from '@angular/common';
import {AppComponent} from './app';
import { disableDeprecatedForms, provideForms } from '@angular/forms';
import {appRouterProviders} from './app.routes';
import {HTTP_PROVIDERS, Http} from '@angular/http';
import {AuthHttp, AuthConfig} from 'angular2-jwt';
bootstrap(AppComponent, [
HTTP_PROVIDERS,
appRouterProviders,
bind(LocationStrategy).toClass(HashLocationStrategy),
provideForms(),
provide(AuthConfig, { useFactory: () => {
return new AuthConfig();
}}),
AuthHttp
]).catch((err: any) => console.error(err));
示例8: enableProdMode
import { APP_ROUTER_PROVIDERS } from './app.routes';
if (!process.env.isDevelopment) {
enableProdMode();
}
bootstrap(AppComponent, [
disableDeprecatedForms(),
provideForms(),
APP_ROUTER_PROVIDERS,
HTTP_PROVIDERS,
Overlay,
OverlayContainer,
provide(ToastrService, {
useFactory: (overlay: Overlay, injector: Injector) => {
const customConfig = new ToastrConfig();
customConfig.positionClass = 'toast-bottom-right';
return new ToastrService(customConfig, overlay, injector);
},
deps: [Overlay, Injector]
}),
provide(AuthHttp, {
useFactory: (http) => {
return new AuthHttp(new AuthConfig({
tokenGetter: (() => sessionStorage.getItem('accessToken'))
}), http);
},
deps: [Http]
})
])
.catch(err => console.error(err));
示例9: bootstrap
import { APP_BASE_HREF } from '@angular/common';
import { enableProdMode, provide } from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { ROUTER_PROVIDERS } from '@angular/router';
import { AppComponent } from './base';
if ('<%= ENV %>' === 'prod') { enableProdMode(); }
/**
* Bootstraps the application and makes the ROUTER_PROVIDERS and the APP_BASE_HREF available to it.
* @see https://angular.io/docs/ts/latest/api/platform-browser-dynamic/index/bootstrap-function.html
*/
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, { useValue: '<%= APP_BASE %>' })
]);
// In order to start the Service Worker located at "./worker.js"
// uncomment this line. More about Service Workers here
// https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
//
// if ('serviceWorker' in navigator) {
// (<any>navigator).serviceWorker.register('./worker.js').then((registration: any) =>
// console.log('ServiceWorker registration successful with scope: ', registration.scope))
// .catch((err: any) =>
// console.log('ServiceWorker registration failed: ', err));
// }
示例10: provide
import { RouterConfig } from '@angular/router';
import { provideRouter, ExtraOptions } from '@angular/router/src/common_router_providers';
import {NSRouterLink} from './ns-router-link';
import {PageRouterOutlet} from './page-router-outlet';
import {NSLocationStrategy} from './ns-location-strategy';
import {NativescriptPlatformLocation} from './ns-platform-location';
import {RouterExtensions} from './router-extensions';
export {routerTraceCategory} from "../trace";
export {PageRoute} from './page-router-outlet';
export {RouterExtensions} from './router-extensions';
export const NS_ROUTER_PROVIDERS: any[] = [
NSLocationStrategy,
provide(LocationStrategy, { useExisting: NSLocationStrategy }),
NativescriptPlatformLocation,
provide(PlatformLocation, { useClass: NativescriptPlatformLocation }),
RouterExtensions
];
export const NS_ROUTER_DIRECTIVES: Type[] = [
NSRouterLink,
PageRouterOutlet
];
export function nsProvideRouter(config: RouterConfig, opts: ExtraOptions): any[] {
return [
...NS_ROUTER_PROVIDERS,
...provideRouter(config, opts) // NOTE: use provideRouter form common_router_providers - it doesnt include BrowserPlatformLocation