0

I'm working with Angular2 beta.8 and I'm currently trying to use gulp to build the project. I used to have it in Plunker, where this:

export class Class {
  name:string;
  constructor() {
    this.name='Angular 2';
    function();
  }    
}

worked. Now compiler suggests me to use this.function() (e:I failed to mention that not only it suggests me to do that, it does so while throwing an error, which is the reason for looking for a correct way of doing all this), which doesn't work. Neither do any combination of the two answers I link below, which I've tried like this:

declare var function: any;

export class Prueba {
  holder: any;
    this.holder = new function();

So I would like to know how to go about this. The folder distribution would be like this:

src
 |function.js()
 |component.ts

And so I want to call function.js inside my component and as I said, I managed to do it in plunker, but as with many other things, when trying to do it with gulp and compiling and such it won't work. In the index.html I have:

    <script src="src/burbuja.js" language="JavaScript"></script>

which should be enough? but somehow isn't.

What am I failing to see? Looking around I've found this two threads:

Angular 2 typescript invoke javascript function

Using a Javascript Function from Typescript

But when trying to implement it I keep getting function() is not defined, no matter what. The main difference I've found is that I have a component and the examples do not but if that affects anything I do not reach that far, I don't feel it should though.

As an observation, when I look at the stacktrace, I see the javascript originated from my typescript code (I know next to 0 javascript), and indeed I can't find any other previous declaration of function, so I guess that's where the problem is coming from, though I'm not sure why this type of declaration of the variable "Myfunction" does not get transpiled to anything, this is the only time in the javascript generated where function appears:

Task = (function () {
            function Task() {
                this.name = 'Angular 2';
                this.holder = new Myfunction();
            }
            Task = __decorate([...
......
Community
  • 1
  • 1
monkey intern
  • 705
  • 3
  • 14
  • 34

0 Answers0