SkyWalker
SkyWalker

Reputation: 14309

AngularJS: Property 'ngEnter' does not exist on type 'IAttributes'

I'm using Typescript and migrating the DefinitelyTyped definitions for angular from 1.3 to 1.6.2 leads to the following error in my MainModule.ts:

Error:(14, 43) TS2339:Property 'ngEnter' does not exist on type 'IAttributes'.

The code that triggers the compiler error is defining the angularjs module:

angular.module('myApp', ['ngRoute', 'ui.bootstrap', 'ui.bootstrap.modal', 'smart-table'])
    .service('appService', AppService)
    .controller('MainCtrl', MainCtrl)
    .controller('uploadTSCtrl', UploadTSCtrl)
    .controller('inputCtrl', InputCtrl)
    .controller('reportCtrl', ReportCtrl)
    .directive('ngEnter', function () {
        return function (scope, element, attrs) {
            element.bind("keydown keypress", function (event) {
                if(event.which === 13) {
                    scope.$apply(function (){
                        scope.$eval(attrs.ngEnter); // <<<<<<<<<<<<< here
                    });
                    event.preventDefault();
                }
            });
        };
    })

I could not find a migration guide or anything like it from 1.x to 1.6.2 and don't know how to fix it ..

Upvotes: 0

Views: 372

Answers (2)

SkyWalker
SkyWalker

Reputation: 14309

For completeness, I also found another way using a pre-built directive that can just be plugged in for this OP purpose: typescript-key-enter-directive

Upvotes: 0

I also encountered such problems and just made

scope.$eval(attrs['ngEnter']);

OR

scope.$eval((attrs as any).ngEnter);

to avoid the problem.

Upvotes: 1

Related Questions