[英]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
: 我正在使用Typescript并将从Angle的DefinitelyTyped定义从1.3迁移到1.6.2导致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: 触发编译器错误的代码正在定义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();
}
});
};
})
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 .. 我找不到从1.x到1.6.2的迁移指南或类似的东西,也不知道如何解决..
I also encountered such problems and just made 我也遇到了这样的问题,
scope.$eval(attrs['ngEnter']);
OR 要么
scope.$eval((attrs as any).ngEnter);
to avoid the problem. 避免问题。
为了完整起见,我还发现了另一种使用预构建指令的方法,可以为此操作插入该指令 : typescript-key-enter-directive
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.