AngularJS: 属性 'ngEnter' 在类型 'IAttributes' 上不存在
AngularJS: Property 'ngEnter' does not exist on type 'IAttributes'
我正在使用 Typescript 并迁移 DefinitelyTyped definitions for angular from 1.3 to 1.6.2 导致我的 MainModule.ts
出现以下错误:
Error:(14, 43) TS2339:Property 'ngEnter' does not exist on type 'IAttributes'.
触发编译器错误的代码定义了angularjs模块:
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();
}
});
};
})
我找不到从 1.x 到 1.6.2 的迁移指南或类似的东西,也不知道如何修复它..
我也遇到过这样的问题,刚刚做了
scope.$eval(attrs['ngEnter']);
或
scope.$eval((attrs as any).ngEnter);
避免问题。
为了完整起见,我还找到了另一种使用预建指令的方法,该指令可以为此 OP 目的插入:typescript-key-enter-directive
我正在使用 Typescript 并迁移 DefinitelyTyped definitions for angular from 1.3 to 1.6.2 导致我的 MainModule.ts
出现以下错误:
Error:(14, 43) TS2339:Property 'ngEnter' does not exist on type 'IAttributes'.
触发编译器错误的代码定义了angularjs模块:
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();
}
});
};
})
我找不到从 1.x 到 1.6.2 的迁移指南或类似的东西,也不知道如何修复它..
我也遇到过这样的问题,刚刚做了
scope.$eval(attrs['ngEnter']);
或
scope.$eval((attrs as any).ngEnter);
避免问题。
为了完整起见,我还找到了另一种使用预建指令的方法,该指令可以为此 OP 目的插入:typescript-key-enter-directive