// 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 ];
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) {
beforeEachProviders(() => [ provide(TestProviderConfig, {useValue: config}), TestProvider ]);
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}`)); } }) ];
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})]);
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); });
beforeEachProviders(() => [provide(TodoService, {useClass: MockTodoService})]);
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] } ) ];
beforeEachBindings(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
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}) ];