Angular 2 Meteor Dependency Injection


#1

I’m new to both Meteor and Angular but am evaluating both with a view to porting an existing application. I’ve followed with interest the excellent Angular 2 tutorial.

A big attraction for me of Angular 2 is its emphasis on dependency injection using services, nice encapsulated components etc. Meteor OTOH seems to offer a very good publish/subscribe infrastructure along with all the advatages of node.js.

However the use of MeteorComponent in the tutorial seems to work against Angular 2’s dependency injection approach, seemingly closely coupling each component with the details of Meteor’s publish/subscribe mechanism.

I’d like to see an implementation (or maybe try to implement one myself) of a Meteor/Angular2 hybrid which uses an injected angular service to separate the details of the Publish/Subscribe layer from the component implementation.

Does anyone have any examples of such an approach or arguments/suggestions for or against trying it?

Thanks!


Is it already good time to start new app with Angulas2 (beta)?
#2

I’ve raised an issue on this subject here:


#3

Hi @sirockin, Dependency Injection is working perfect. When you have Service, just use it directly like in normal Angular 2 apps.


#4

For some reason, Dependency injection does not quite work for me, to work around that, I need to hand-code the dependencies instead of using the decorators. For example

@Injectable() //this does not work
export class Car {
    static get parameters() {
        return [[Engine, Wheel]]; // Have to hand code this static parameters as a workaround.
    }

    constructor( public engine:Engine, public wheel:Wheel ) {
    }
}

#5

Which Angular 2 and Meteor version are you using?

Have you imported Injectable?

import { Injectable } from ‘@angular/core’;


#6

Yes, Injectable is declared on both the Car class and Engine class in the sample above, and the Injectable is imported from @angular/core

I use Angular 2.0.0-rc1 and Meteor 1.3.2.4, and I also remove and readd all the meteor packages just to make sure they stay up to date as well.

The runtime error I have got is Uncaught Cannot resolve all parameters for 'Car'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Car' is decorated with Injectable.


#7

@tangentlin aybe create an issue on github with a reproduction (small demo)?