我正在使用 Typescript 并迁移 DefinitelyTyped Angular 定义从 1.3 到 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);
避免这个问题。
关于javascript - AngularJS:类型 'ngEnter' 上不存在属性 'IAttributes',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42807428/