angularjs – 使用Typescript在Ionic 1应用程序中插入Cordova

前端之家收集整理的这篇文章主要介绍了angularjs – 使用Typescript在Ionic 1应用程序中插入Cordova前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Typescript的新手.我刚刚使用Typescript开始了一个Ionic 1.2.4(Angular)项目.转换时,我收到错误消息属性’Keyboard’在类型’CordovaPlugins’上不存在,因为以下函数传递给文件run.ts中的angular.module.run()
///<reference path="../../typings/tsd.d.ts"/>

export function onRun($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  })
}

实际上已经安装了cordova插件,它的类型定义文件肯定存在.这是文件tsd.d.ts.

/// <reference path="angularjs/angular.d.ts" />
/// <reference path="cordova/cordova.d.ts" />
/// <reference path="cordova/plugins/BatteryStatus.d.ts" />
/// <reference path="cordova/plugins/Camera.d.ts" />
/// <reference path="cordova/plugins/Contacts.d.ts" />
/// <reference path="cordova/plugins/Device.d.ts" />
/// <reference path="cordova/plugins/DeviceMotion.d.ts" />
/// <reference path="cordova/plugins/DeviceOrientation.d.ts" />
/// <reference path="cordova/plugins/Dialogs.d.ts" />
/// <reference path="cordova/plugins/FileSystem.d.ts" />
/// <reference path="cordova/plugins/FileTransfer.d.ts" />
/// <reference path="cordova/plugins/Globalization.d.ts" />
/// <reference path="cordova/plugins/InAppBrowser.d.ts" />
/// <reference path="cordova/plugins/Keyboard.d.ts" />
/// <reference path="cordova/plugins/Media.d.ts" />
/// <reference path="cordova/plugins/MediaCapture.d.ts" />
/// <reference path="cordova/plugins/NetworkInformation.d.ts" />
/// <reference path="cordova/plugins/Push.d.ts" />
/// <reference path="cordova/plugins/Splashscreen.d.ts" />
/// <reference path="cordova/plugins/StatusBar.d.ts" />
/// <reference path="cordova/plugins/Vibration.d.ts" />
/// <reference path="cordova/plugins/Websql.d.ts" />
/// <reference path="ionic/ionic.d.ts" />
/// <reference path="jquery/jquery.d.ts" />

我还尝试直接在run.ts中放置键盘的类型定义. ///< reference path =“../../ typings / cordova / plugins / Keyboard.d.ts”/>

我不希望插件实际注册,因为’cordova.js’在应用程序构建/打包之前不可用.然而,我想知道如何让Typescript识别键盘确实存在于cordova.plugins上的类型defs.否则,如何在转换过程中避免此错误

安装打字稿定义时,我没有安装cordova-ionic. “标准”cordova键盘插件与cordova-ionic键盘插件截然不同.

tsd install cordova-ionic –save修复了这个问题.

哎呦.

原文链接:https://www.f2er.com/angularjs/240447.html

猜你在找的Angularjs相关文章