Javascript AngularJS,通过服务传递变量的类型脚本

Javascript AngularJS,通过服务传递变量的类型脚本,javascript,angularjs,Javascript,Angularjs,我目前正在使用AngularJS开发一个应用程序,现在的问题是,当我点击菜单按钮时,我需要传递一个URL,这样我就可以在另一个控制器的另一个视图的iframe中使用该URL。我一直在尝试很多事情,并且像整个Stackoverflow一样运行,但是我找不到解决问题的方法 我的服务: module Services { export class PassUrlService { getUrl; setUrl; givenUrl;

我目前正在使用AngularJS开发一个应用程序,现在的问题是,当我点击菜单按钮时,我需要传递一个URL,这样我就可以在另一个控制器的另一个视图的iframe中使用该URL。我一直在尝试很多事情,并且像整个Stackoverflow一样运行,但是我找不到解决问题的方法

我的服务:

module Services {
    export class PassUrlService {

        getUrl;
        setUrl;
        givenUrl;

        constructor($scope) {
            this.getUrl = function() {
                return this.givenUrl;
            }

            this.setUrl = function (value: string) {
                this.givenUrl = value;
            }
        }

    }
}
module Controllers {
    export class MainController {

        data = [];
        sce;
        IframeUrl;

        constructor($scope, $sce) {
            $scope.data = this.data;
            $scope.vm = this;
            this.sce = $sce;
        }

        setIframeUrl = function (url) {
            this.IframeUrl = Services.PassUrlService.setUrl(this.sce.trustAsResourceUrl(url));
            debugger;
        }

    }
}
我的控制器:

module Services {
    export class PassUrlService {

        getUrl;
        setUrl;
        givenUrl;

        constructor($scope) {
            this.getUrl = function() {
                return this.givenUrl;
            }

            this.setUrl = function (value: string) {
                this.givenUrl = value;
            }
        }

    }
}
module Controllers {
    export class MainController {

        data = [];
        sce;
        IframeUrl;

        constructor($scope, $sce) {
            $scope.data = this.data;
            $scope.vm = this;
            this.sce = $sce;
        }

        setIframeUrl = function (url) {
            this.IframeUrl = Services.PassUrlService.setUrl(this.sce.trustAsResourceUrl(url));
            debugger;
        }

    }
}
我得到的错误是:

错误TS2339:类型“typeof”上不存在属性“setUrl” PassUrlService’


我希望有人能帮我解决这个问题,提前谢谢

我认为您没有在控制器中注入服务,请尝试下面的示例

service: Services.PassUrlService

constructor($scope, $sce, service: Services.PassUrlService ) {
        $scope.data = this.data;
        $scope.vm = this;
        this.sce = $sce;
        this.service = service
    }

我认为您没有在控制器中注入服务,请尝试下面的示例

service: Services.PassUrlService

constructor($scope, $sce, service: Services.PassUrlService ) {
        $scope.data = this.data;
        $scope.vm = this;
        this.sce = $sce;
        this.service = service
    }