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


TypeScript core.provide函數代碼示例

本文整理匯總了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
];
開發者ID:ASDAlexey,項目名稱:angular2-jwt-express,代碼行數:29,代碼來源:providers.ts

示例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) {
開發者ID:Jefftopia,項目名稱:angular2-tutorial,代碼行數:31,代碼來源:main.ts

示例3: beforeEachProviders

 beforeEachProviders(() => [
   provide(TestProviderConfig, {useValue: config}),
   TestProvider
 ]);
開發者ID:AlexYankee,項目名稱:ng2-starter,代碼行數:4,代碼來源:test-provider.spec.ts

示例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}`));
    }
  })
];
開發者ID:appmite,項目名稱:karaoke-reading-web,代碼行數:22,代碼來源:book-providers.ts

示例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})]);
開發者ID:Amzikan,項目名稱:protractor,代碼行數:7,代碼來源:boot.ts

示例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);
  });
開發者ID:ebarabanovska,項目名稱:OPEN_Launcher,代碼行數:30,代碼來源:app.ts

示例7: beforeEachProviders

 beforeEachProviders(() => [provide(TodoService, {useClass: MockTodoService})]);
開發者ID:AliMD,項目名稱:generator-ng-fullstack,代碼行數:1,代碼來源:todo-cmp_test.ts

示例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]
        }
    )
];
開發者ID:Rachnerd,項目名稱:angular2,代碼行數:16,代碼來源:index.ts

示例9: beforeEachBindings

 beforeEachBindings(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
開發者ID:hankduan,項目名稱:angular,代碼行數:1,代碼來源:router_integration_spec.ts

示例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})
];
開發者ID:clankford,項目名稱:angular2-routing,代碼行數:29,代碼來源:AuthService.ts


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