Closed artaommahe closed 8 years ago
I'm not able to reproduce it (exaple attempt). Could you post a live reproduction (e.g. using CodePen, Plnkr etc) ?
One nice solution to the general problem of injecting things and TypeScript that we've come up with is to only inject the $injector (if possible).
class MyService {
private $injector : ng.auto.IInjectorService;
static $inject = ['$injector'];
constructor($injector : ng.auto.IInjectorService) {
this.$injector = $injector;
}
someMethod() {
let $rootScope = this.$injector.get<ng.IRootScopeService>('$rootScope');
// ...
}
}
This avoids needing to have all the injectables you want to use as instance variables on your service.
On the downside, using the $injector
might cover up cyclic dependencies.
This is not specific to TypeScript; it's also true with JavaScript.
@artaommahe See my answer on SO.
I think this is expected behavior. This could also happen with non-Typescript code. You simply should not watch the whole instance as @thorn0 has written in his SO answer.
Using typescript class for service that injects $rootScope like this
will falls with this errors
it happens becasue $rootScope saves as accesible function variable after transpiling
and angular trying to hang watch
and falls with copy
based on this staskoverflow question http://stackoverflow.com/questions/33814040/how-do-i-inject-rootscope-using-typescript-static-injector-pattern/35710099#35710099