shuhei / babel-plugin-angular2-annotations

A babel transformer plugin for Angular 2 annotations
80 stars 9 forks source link

Not working on services #26

Closed lghiur closed 8 years ago

lghiur commented 8 years ago

Hello @shuhei ,

I have the following code, but http is not recognized inside the constructor, it logs undefined:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { NgRedux } from 'ng2-redux';

import AppStore from 'app/common/components/store/js/store';

@Injectable()
export class UserActions {
  constructor (http: Http) {
    console.log(http);
  }

I want to add that it works really well inside a component. I can't find the reason for that. Do you have any advices?

Many thanks, Laurentiu

shuhei commented 8 years ago

Hi, how do you create an instance of UserActions? It should be instantiated by Angular's injector to get http injected.

lghiur commented 8 years ago

Ha, that was it, silly me, thanks a lot, you saved my day :+1:

constructor (actions: UserActions, router: Router, http: Http) {
    this.ngRedux = new NgRedux();
    this.ngRedux.provideStore(AppStore);
    this.actions = actions;

This works now.

shuhei commented 8 years ago

Glad to hear that :+1: