0

Currently, I'm trying to use work with the online view of the document and I came across this website.https://rollmyfile.com/.

when I head towards the developer APIs https://rollapp.readme.io/v1.0/docs/rollmyfile-js-api. I find I can read any document by passing the URL. But I'm working on angular 4 which uses typescript so I did call out

so I placed the js code in my index.html

index.html

<script type="text/javascript" src="https://api.rollapp.com/1/js/rollmyfile.js"></script>

now I need to make use of this js file to pass the Url to it something this.

<script type="text/javascript">
    var key = "SeCur3AP1K3y";

    var rollMyFile = new RollMyFile(key);
</script>
rollMyFile.openFileByUrl("https://www.example.com/documentation/overview.docx");

so, I need to make use of .openFileByUrl in my .component.ts

I have referred the path as well in my .component.ts something like this

///<reference path="https://api.rollapp.com/1/js/rollmyfile.js"/>

but still, I'm not able to create an instance of RollMyFile.

I'm getting [ts] Cannot find name 'RollMyFile' error.

Is there something that I'm doing wrong?

4
  • you should probably declare your RollMyFile somewhere in the components you need it declare RollMyFile: any. Would be better if you had typings but this should be enough to get it working. Commented Apr 3, 2018 at 12:39
  • i did it but its throwing me an error Cannot find name 'RollMyFile'. Did you mean the instance member 'this.RollMyFile' Commented Apr 3, 2018 at 12:42
  • Can you please add the component where you try this call to your question? Commented Apr 3, 2018 at 13:04
  • Hint: <reference path... doesn't do what you think it does Commented Apr 3, 2018 at 14:07

2 Answers 2

1

You need to declare RollMyFile on top in order to use that function in your TS file

 declare const RollMyFile: any;

ngOnInit() {
 console.log("hi");
 var key = "SeCur3AP1K3y";
 var rollMyFile = new RollMyFile(key);
 console.log('rollMyFile',rollMyFile)
}

This console giving me error because of having wrong secret key.

Sign up to request clarification or add additional context in comments.

2 Comments

Currently, got the valid key but when I follow your steps it is throwing an error. ERROR TypeError: Cannot set property '_apiHost' of undefined
Add new keyword in from of function name..Check updated solution
0

try this in your component :

declare RollMyFile: any;
constructor(private _script: ScriptLoaderService) {}
ngOnInit() {
    this._script.load('body', 'https://api.rollapp.com/1/js/rollmyfile.js')
        .then(result => {
        });
    }
}

and use RollMyFile in your code something like this:

(<any>RollMyFile).somfunction();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.