0

I'm currently working on an application using AngularJS, now the thing is, I need to pass an URL when I click on a menu button so I can use that URL in an iframe on in another view with another controller. I've been trying a lot of things and ran through like whole Stackoverflow, but I couldn't find a solution for my problem..

My service:

module Services {
    export class PassUrlService {

        getUrl;
        setUrl;
        givenUrl;

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

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

    }
}

My controller:

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;
        }

    }
}

The error I'm getting is:

error TS2339: Property 'setUrl' does not exist on type 'typeof PassUrlService'.

I hope someone can help me solving this problem, thanks in advance!

1 Answer 1

2

I think you are not injecting your Service in the controller, try with the sample below

service: Services.PassUrlService

constructor($scope, $sce, service: Services.PassUrlService ) {
        $scope.data = this.data;
        $scope.vm = this;
        this.sce = $sce;
        this.service = service
    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.