J Doe J Doe - 2 years ago 67
Javascript Question

Accessing custom service from event

I'm attempting to access a custom service from a custom event yet wheneven the event is fired the service reference is null

selector: "my-component",
template: mySource,
legacy: { transclude: true }
export class myComponent {
@Inject("$scope") private $scope: ng.IScope,
private myService: MyService) {

$scope.$on('$routeChangeSuccess', function (event) {

when myService is referenced the following error is shown:

Cannot read property 'myService' of null

Answer Source

The solution is not to refer to myService from within myComponent prepended with


but instead use

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download