0

I have an angular controller (generated by typescript):

class FileManagerController {
   ... 
   constructor($scope) {
      $scope.vm = this;
      ...
   }

   ...functions...
}

How can I use this controller in the directive?

var myApp = angular.module('myApp', ])
  .directive('ngFilemanager', function () {
        return {
            restrict: 'EA',
            require: '^ngModel',
            scope: {
                ngModel: '='
            },
            templateUrl: '/templates/filemanager.html',
            controller: ???
        }
   });

1 Answer 1

1

If the TypeScript class is not declared in a module, it would be as simple as:

....
controller: FileManagerController,
...

If you take a look at the Javascript compiled output of FileManagerController, you will find the function.

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

3 Comments

I copy pasted the function and got the error FileManagerController is not a function
Again, check the compiled TypeScript file. It does define a FileManagerController; if there are no modules, it will be global. You will also have to make sure that FileManagerController.js is loaded before the angular module. Make sure FileManagerController is loaded by calling it from the console.
my controller constructor is called twice now?

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.