How to use the angular2/core.Injectable function in angular2

To help you get started, we’ve selected a few angular2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / universal / modules / universal / server / src / router / node_platform_location.ts View on Github external
public state: any,
    public title: string,
    public url: string
  ) {}
}

// TODO(gdi2290): toJSON
class PopStateEvent {
  public type = 'popstate';

  constructor(
    public state: any
  ) {}
}

@Injectable()
export class NodePlatformLocation extends PlatformLocation {
  private _loc: LocationConfig;
  private _stack: Array = [];
  private _stackIndex = -1;
  private _popStateListeners: Array = [];
  private _baseHref: string = '/';

  constructor(
    @Inject(REQUEST_URL) requestUrl: string,
    @Optional() @Inject(APP_BASE_HREF) baseUrl?: string) {
    super();
    this._baseHref = baseUrl || '/';
    this.pushState(null, null, joinWithSlash(this._baseHref, requestUrl));
  }

  get search(): string { return this._loc.search; }
github mschwarzmueller / RecipeBook / dev / shared / shopping-list.service.ts View on Github external
import {Injectable} from 'angular2/core';
import {Ingredient} from "./ingredient";
import {SHOPPING_LIST} from "../mock/shopping-list";

@Injectable()
export class ShoppingListService {
	getAllItems() {
		return SHOPPING_LIST;
	}

	getItem(index: number) {
		return SHOPPING_LIST[index];
	}

	getIndexOfItem(item: Ingredient) {
		console.log("getIndexOfItem:", item);
		console.log("SHOPPING_LIST:", SHOPPING_LIST);
		console.log("SHOPPING_LIST.indexOf(item):", SHOPPING_LIST.indexOf(item));		
		return SHOPPING_LIST.indexOf(item);
	}
github bradyhouse / house / fiddles / angular2 / fiddle-0024-Dashboard / src / component / chart / ChartDataService.ts View on Github external
import {Component, enableProdMode, Injectable} from 'angular2/core';
import {Http, Headers, HTTP_PROVIDERS} from 'angular2/http';
import 'rxjs/add/operator/map';



@Injectable()
export class ChartDataService {
    constructor(private http: Http) {}
    request(url:String) {
        return this.http
            .get(url)
            .map(res => res.json());


    }
}
github angular / universal / modules / universal / server / src / router / server_router.ts View on Github external
this.href = parsed.href;
    this.pathname = parsed.pathname;
    this.port = parsed.port;
    this.protocol = parsed.protocol;
    this.search = parsed.search;
    this.origin = parsed.protocol + '//' + parsed.hostname + ':' + parsed.port;
  }
  reload(forcedReload?: boolean): void {/*TODO*/}
  replace(url: string): void {
    this.assign(url);
  }
  toString(): string { /*TODO*/ return ''; }
}


@Injectable()
export class ServerLocationStrategy extends LocationStrategy {
  private _location: Location = new MockServerLocation();
  private _history:  History = new MockServerHistory();
  private _baseHref: string = '/';

  constructor(
    @Optional() @Inject(BASE_URL) url?: string,
    @Optional() @Inject(APP_BASE_HREF) baseUrl?: string) {
    super();
    this._baseHref = baseUrl;
    this._location.assign(url || '/');
  }

  onPopState(fn: EventListener): void {/*TODO*/}

  getBaseHref(): string { return this._baseHref; }
github DSpace-Labs / angular2-ui-prototype / app / dspace / dspace.service.ts View on Github external
import {EventEmitter, Injectable} from 'angular2/core';
import {Observable, Observer} from 'rxjs/Rx';

import {HttpService} from '../utils/http.service';

@Injectable()
export class DSpaceService {

    private REST: string;

    private url: String;

    private listing: Observer;
    
    private store: { directory: Object[] };

    directory: Observable;

    emitter: EventEmitter;

    constructor(private httpService: HttpService) {
        this.REST = '/tdl-rest';
github DSpace-Labs / angular2-ui-prototype / src / app / utils / websocket.service.ts View on Github external
import {Injectable, EventEmitter} from 'angular2/core';
import {Observable} from 'rxjs/Rx';

import {$WebSocket} from 'angular2-websocket/angular2-websocket'

@Injectable()
export class WebSocketService {

    webSocket: WebSocket;

    pending: Array;

    emitter: EventEmitter;

    resolveMap: Map;

    isReady: boolean;

    constructor() {

        this.webSocket = new WebSocket("ws://localhost:3001");
github jarves / jarves / Resources / public / services / WindowManagement.ts View on Github external
options: Object,
    parentWindowId: number,
    isInline: boolean,
    parameters: Object,
    inFront: boolean
}

export interface WindowList {
    [windowId: number]: WindowInfo
}

export interface JarvesWindowList {
    [windowId: number]: JarvesWindow
}

@Injectable()
export default class WindowManagement {

    public activeWindowList:WindowList = {};
    public activeWindowId = -1;
    public currentWindowIndex = 0;
    public activeWindow:JarvesWindow = null;
    public jarvesWindows:JarvesWindowList = {};

    constructor(protected jarves:Jarves) {
        this.activeWindowList = {};
        this.activeWindowId = -1;
        this.currentWindowIndex = 0;
    }

    protected updateUrlHashActive:boolean = false;
github shlomiassaf / ngx-modialog / src / components / angular2-typeahead / components / typeahead.ts View on Github external
import {
    Directive,
    DynamicComponentLoader,
    ElementRef,
    ComponentRef,
    Renderer,
    Injectable,
    Injector,
    provide} from 'angular2/core';


import {TypeaheadResultContainer} from './typeaheadResultContainer';

@Injectable()
@Directive({
    selector: '[typeahead]',
    host: {
        '(keyup)': 'onKeyup($event)'
    },
    properties: [
        'data:typeahead'
    ]
})
export class Typeahead {
    public results;
    private data:any;
    private resultElement: Promise;
    private resultInstance: TypeaheadResultContainer;

    constructor(private componentLoader: DynamicComponentLoader,
github ild-games / duckling-legacy / src / duckling / canvas / tools / tool.service.ts View on Github external
import {Injectable} from 'angular2/core';

import {ToolbarOption} from '../../controls';
import {EntityCreatorTool, BaseTool, EntityMoveTool} from '../tools';

/**
 * Provide access to tools for the canvas.
 * @return {[type]} [description]
 */
@Injectable()
export class ToolService {
    private _tools : {[key:string]:BaseTool} = {};
    private _default : BaseTool;

    constructor(entityCreator : EntityCreatorTool,
                entityMoveTool : EntityMoveTool) {
        this._default = entityMoveTool;
        this.addTool(entityCreator);
        this.addTool(entityMoveTool);
    }

    /**
     * The default tool.
     */
    get defaultTool() : BaseTool {
        return this._default;
github robwormald / ngrx-rest-app / client / app / items.ts View on Github external
//-------------------------------------------------------------------
const BASE_URL = 'http://localhost:3000/items/';
const HEADER = { headers: new Headers({ 'Content-Type': 'application/json'})};

export interface Item{
  id: number;
  name: string;
  description: string;
}

export interface AppStore {
  items: Item[],
  selectedItem: Item
}

@Injectable()
export class ItemsService {
  items: Observable>;

  constructor(private http: Http, private store: Store){
    this.items = store.select('items');
  }

  loadItems() {
    this.http.get(BASE_URL)
      .map(res => res.json())
      .map(payload => ({type: 'ADD_ITEMS', payload}))
      .subscribe(action => this.store.dispatch(action));
  }

  saveItem(item: Item) {
    (item.id) ? this.updateItem(item) : this.createItem(item);