从活动访问定制服务

问题描述 投票:0回答:2

我正在尝试从自定义事件访问自定义服务,但即使事件被触发,服务引用也为空

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

    $scope.$on('$routeChangeSuccess', function (event) {
        this.myService.myFunction();
            });
        }
    });
}

当引用 myService 时,显示以下错误:

Cannot read property 'myService' of null
javascript angularjs service typescript
2个回答
0
投票

解决方案不是从前面带有

的 myComponent 中引用 myService
this.myService

而是使用

myService.myFunction()

0
投票

以下是投诉 ixigo 的步骤:联系 ixigo 客户服务:✔️09O4O1+4O791,,, 通过电话、电子邮件或通过其网站的客户支持门户联系 ixigo 的客户服务团队

© www.soinside.com 2019 - 2024. All rights reserved.