[英]AngularJS: Property 'ngEnter' does not exist on type 'IAttributes'
我正在使用Typescript並將從Angle的DefinitelyTyped定義從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);
避免問題。
為了完整起見,我還發現了另一種使用預構建指令的方法,可以為此操作插入該指令 : typescript-key-enter-directive
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.