无法使Azure与Ionic2 / Angular2 / Cordova应用

时间:2016-10-23 16:33:39

标签: cordova typescript ionic2 azure-mobile-services visual-studio-cordova

我正在使用基础Ionic2 Blank应用程序。当我在home.ts中使用以下行实例化Azure时

import azureMobileClient from 'azure-mobile-apps-client';

,它没有错误地部署。故障只是纹波上的空白屏幕或设备上的空白屏幕。我没有看到构建中的任何错误。

当前设置: Win10 x64 Visual Studio 2015社区 Cordova CLI:6.3.1 Ionic Framework版本:2.0.0-rc.1 Ionic CLI版本:2.1.1 Ionic App Lib版本:2.1.1 节点版本:v4.6.0

以下是我采取的步骤

  1. 从Ionic 2(Beta 10)
  2. 创建新项目
  3. 空白还原依赖项
  4. 跑" npm安装azure-mobile-apps-client" (收到npm WARN enoent ENOENT)
  5. 编辑package.json,添加" azure-mobile-apps-client":" ^ 2.0.0-rc1"
  6. 在app文件夹中,创建新文件declarations.d.ts。
  7. 添加
        声明模块' azure-mobile-apps-client&#39 ;; to declarations.d.ts(Deploy仍然显示主页)
  8. 编辑home.ts,补充道 从&azunk-mobile-apps-client'中导入azureMobileClient; 在导入{NavController}下来自' ionic-angular&#39 ;; (项目部署但显示 空白屏幕)
  9. 的package.json

    {
      "name": "io.cordova.myapp3e6a78",
      "private": true,
      "version": "0.0.1",
      "description": "ionic2-ts-blank: An Ionic project",
      "dependencies": {
        "@angular/common": "2.0.0-rc.3",
        "@angular/compiler": "2.0.0-rc.3",
        "@angular/core": "2.0.0-rc.3",
        "@angular/platform-browser": "2.0.0-rc.3",
        "@angular/platform-browser-dynamic": "2.0.0-rc.3",
        "@angular/http": "2.0.0-rc.3",
        "es6-shim": "^0.35.0",
        "ionic-angular": "2.0.0-beta.10",
        "ionic-native": "1.2.4",
        "ionicons": "3.0.0",
        "reflect-metadata": "^0.1.3",
        "rxjs": "5.0.0-beta.6",
        "zone.js": "^0.6.12",
        "azure-mobile-apps-client": "^2.0.0-rc1"
      },
      "devDependencies": {
        "del": "2.2.0",
        "gulp": "3.9.1",
        "gulp-watch": "4.3.5",
        "ionic-gulp-browserify-typescript": "2.0.0",
        "ionic-gulp-fonts-copy": "^1.0.0",
        "ionic-gulp-html-copy": "^1.0.0",
        "ionic-gulp-sass-build": "^1.0.0",
        "ionic-gulp-scripts-copy": "^2.0.0",
        "run-sequence": "1.1.5",
        "typings": "^1.3.1"
      },
      "cordovaPlugins": [
        "cordova-plugin-whitelist",
        "cordova-plugin-console",
        "cordova-plugin-statusbar",
        "cordova-plugin-device",
        "cordova-plugin-splashscreen",
        "ionic-plugin-keyboard"
      ],
      "cordovaPlatforms": [ ],
      "scripts": {
        "build": "node_modules/.bin/gulp build",
        "typings": "node_modules/.bin/typings install",
        "postinstall": "npm run typings && npm run build"
      }
    }
    

    declarations.d.ts declare module 'azure-mobile-apps-client';

    home.ts

    import {Component} from '@angular/core';
    import {NavController} from 'ionic-angular';
    import azureMobileClient from 'azure-mobile-apps-client';
    
    @Component({
      templateUrl: 'build/pages/home/home.html'
    })
    export class HomePage {
      constructor(private navController: NavController) {
        }
      onLink(url: string) {
          window.open(url);
      }
    }
    

1 个答案:

答案 0 :(得分:0)

您实际上并没有在代码中使用azureMobileClient,除了引入它之外.ENOENT意味着它没有被下载。您需要成功安装npm才能使用它。然后你实际上需要使用它。