本文整理汇总了TypeScript中angular2/core.provide函数的典型用法代码示例。如果您正苦于以下问题:TypeScript provide函数的具体用法?TypeScript provide怎么用?TypeScript provide使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了provide函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: provide
// Angular 2
import {FORM_PROVIDERS} from 'angular2/common';
// Angular 2 Http
import {HTTP_PROVIDERS} from 'angular2/http';
// Angular 2 Router
import {ROUTER_PROVIDERS, APP_BASE_HREF} from 'angular2/router';
// Angular 2 Material
// import {MdRadioDispatcher} from '@angular2-material/radio/radio_dispatcher';
// const MATERIAL_PROVIDERS = [
// MdRadioDispatcher
// ];
/*
* Application Providers/Directives/Pipes
* providers/directives/pipes that only live in our browser environment
*/
export const APPLICATION_PROVIDERS = [
...FORM_PROVIDERS,
...HTTP_PROVIDERS,
// ...MATERIAL_PROVIDERS,
...ROUTER_PROVIDERS,
provide(APP_BASE_HREF, {useValue: '/'}),
];
export const PROVIDERS = [
...APPLICATION_PROVIDERS
];
示例2: createAppStoreFactoryWithOptions
import {bootstrap} from "angular2/platform/browser";
import {provide} from "angular2/core";
import {AppComponent} from "./app-component";
import {HTTP_PROVIDERS} from "angular2/http";
import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from "angular2/router";
import "angular2-materialize";
import {AppStore,createAppStoreFactoryWithOptions} from "angular2-redux";
import users from "./reducers/users-reducer";
const appStoreFactory = createAppStoreFactoryWithOptions({reducers:users,debug:true});
bootstrap(AppComponent, [
provide(AppStore, {useFactory: appStoreFactory}),
ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: HashLocationStrategy}),
HTTP_PROVIDERS
]);
/* tslint:disable */
// polyfill for Object.assign (not part of TS yet)
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
if (!Object.assign) {
Object.defineProperty(Object, "assign", {
enumerable: false,
configurable: true,
writable: true,
value: function(target) {
"use strict";
if (target === undefined || target === null) {
示例3: beforeEachProviders
beforeEachProviders(() => [
provide(TestProviderConfig, {useValue: config}),
TestProvider
]);
示例4: provide
import { provide } from 'angular2/core';
import { FIREBASE_BOOKS_URL } from '../../config';
import { AuthService } from '../auth/auth-service';
import { BookService } from './book-service';
import { BookStore } from './book-store';
export const BOOK_PROVIDERS: any[] = [
provide(BookService, {
deps: [AuthService],
useFactory: (auth: AuthService): BookService => {
return new BookService(new Firebase(`${FIREBASE_BOOKS_URL}/${auth.id}`));
}
}),
provide(BookStore, {
deps: [AuthService],
useFactory: (auth: AuthService): BookStore => {
return new BookStore(new Firebase(`${FIREBASE_BOOKS_URL}/${auth.id}`));
}
})
];
示例5: bootstrap
import {provide} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS, HashLocationStrategy, LocationStrategy} from 'angular2/router';
import {AppRouter} from './app.router';
bootstrap(AppRouter, [ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: HashLocationStrategy})]);
示例6: constructor
export class App {
constructor(private authService: AuthService, private router: Router) { }
isUserLogged(): boolean {
return this.authService.isLogged();
}
getLoggedUser(): string {
return this.authService.getLoggedUser();
}
logout(): void {
this.authService.logout().subscribe((success) => {
if (success) {
this.router.navigate(['/Login']);
}
});
}
}
bootstrap(App, [
HTTP_PROVIDERS,
servicesInjectables,
AUTH_PROVIDERS,
ROUTER_PROVIDERS,
provide(APP_BASE_HREF, { useValue: '/' }),
provide(LocationStrategy, { useClass: HashLocationStrategy })])
.then((appRef) => {
appInjector(appRef.injector);
});
示例7: beforeEachProviders
beforeEachProviders(() => [provide(TodoService, {useClass: MockTodoService})]);
示例8: provide
import {MockBackend} from "angular2/src/http/backends/mock_backend";
import {BaseRequestOptions, Http} from "angular2/http";
import {MyHttp} from "./my-http";
import {provide} from "angular2/core";
export const CUSTOM_HTTP_PROVIDERS = [
MockBackend,
BaseRequestOptions,
provide(Http, {
useFactory: (backend, options) => {
return new MyHttp(backend, options);
},
deps: [MockBackend, BaseRequestOptions]
}
)
];
示例9: beforeEachBindings
beforeEachBindings(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
示例10: login
import { Injectable, provide } from 'angular2/core';
@Injectable()
export class AuthService {
login(user: string, password: string): boolean {
if (user === 'user' && password === 'password') {
localStorage.setItem('username', user);
return true;
}
return false;
}
logout(): any {
localStorage.removeItem('username');
}
getUser(): any {
return localStorage.getItem('username');
}
isLogged(): boolean {
return this.getUser() !== null;
}
}
export var AUTH_PROVIDERS: Array<any> = [
provide(AuthService, {useClass: AuthService})
];