3

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.

1 Answer 1

7

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
            }
   }
Sign up to request clarification or add additional context in comments.

5 Comments

Didnt help. Parameter '$scope' of constructor from exported class has or is using private type 'IMyScope'. tryed different ways of getting rid of this error - made an export for interface, but the previouse error remained.
Add more code. The correct thing is to create your interface. I'll edit my code and show you how I create things.
The code is completely the same that is in example (jsfiddle.net/lsiv568/fsfPe/10) except for basic thing rewritten into typescript (functions, class, link etc...) Error is here: ` return scope.$apply(() => { scope.file = evt.target.result; if (angular.isString(scope.fileName)) { return scope.fileName = name; } });`
im using export class fileDropzone implements ng.IDirective { And i try to extend ng.Iscope, but later i cant use IMyScope for like: public scope: IMyScope, the error: Parameter '$scope' of constructor from exported class has or is using private type 'myExtdScope'
You dont need your scope as a ctor input param. Look at my edit.

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.