0

I have the following code :

(function () {
    'use strict';

    angular.module('gestion').controller(
        'controller',
        controller);

    controller.$inject = ['$mdDialog',
            'locals'];

    function controller($mdDialog, locals) {
        var pm = this;

        pm.cancel = function () {
            $mdDialog.hide();
        };

        pm.validate = function () {
            $mdDialog.hide();
            locals.parentScope.remove();
        };
    }
})();

The problem is that when I run jshint I get this warning message:

If a strict mode function is executed using function invocation, its 'this' value will be undefined.

How can I solve this ?

Edit:

I don't know why this question has been marked as duplicated.

Edit 2:

I solved the problem when I used Controller instead of controller, this has to deal with the Constructor Invocation Pattern, since you should capitalise the first character of the name of a function when you need to construct the object by "new" keyword, which var pm = this does in this case.

Renaud is Not Bill Gates
  • 1,684
  • 34
  • 105
  • 191
  • That seems like a warning, `jshint` is probably not aware of angular context calls so it's printing that – MinusFour Sep 27 '17 at 14:17
  • It is legal. That's a warning not an error. – Quentin Sep 27 '17 at 14:32
  • If you don't think this is a duplicate, please explain why the answers to the duplicate don't solve your problem. Don't just say you don't know why it's a duplicate, that doesn't help anybody understand *why* you don't think it's a duplicate. – Donald Duck Sep 30 '17 at 10:32
  • @DonaldDuck updated with the solution, which has nothing related to the referenced answer. – Renaud is Not Bill Gates Oct 02 '17 at 12:20

0 Answers0