Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scope: { } with parameters in TypeScript

I found one solution for my problem on the internet, but i have a problem that i dont know how to overwrite this:

  restrict: 'A',
  scope: {
    file: '=',
    fileName: '='
  },

into TypeScript.

I have tried this:

            constructor($scope: ng.IScope) {
            var directive: ng.IDirective = {};
            directive.scope = {
                file: '=',
                fileName: '='
            }
        }

But it doesnt help, i still have an error:

The property 'file' does not exist on value of type 'ng.IScope'.

Used this example: http://jsfiddle.net/lsiv568/fsfPe/10/

Maybe (or probably) I am doing something wrong and I have to fix this error in another way, but I hope that you will lead me to the right solution.

like image 579
Artur Wmatko Avatar asked Apr 07 '26 03:04

Artur Wmatko


1 Answers

ng.IScope doesn't have a 'file'\'filename' property. Simply extend the interface. Something like this:

interface IMyScope extends ng.IScope
{
  file: any;
  fileName: any;
}

constructor($scope: IMyScope) {
}

EditHere's how I create directives with a scope:

    class MyDirective implements ng.IDirective {
            public scope: IMyScope;
               // bla bla


            constructor() {
                this.scope = {
                   file: '=',
                   fileName: '='
                };
            }


            this.link = (scope: IMyScope, elem: JQuery, attrs) => {
                 // bla bla
            }
   }
like image 189
Amir Popovich Avatar answered Apr 09 '26 23:04

Amir Popovich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!