【问题标题】:Can't get Azure to work with Ionic2/Angular2/Cordova app无法让 Azure 与 Ionic2/Angular2/Cordova 应用程序一起使用
【发布时间】:2017-03-05 10:46:10
【问题描述】:

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

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

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

当前设置: Win10 x64 Visual Studio 2015 社区 科尔多瓦 CLI:6.3.1 离子框架版本:2.0.0-rc.1 离子 CLI 版本:2.1.1 离子应用程序库版本:2.1.1 节点版本:v4.6.0

这是我采取的步骤

  1. 从 Ionic 2(Beta 10)创建新项目
  2. 空白恢复依赖项
  3. 运行“npm install azure-mobile-apps-client”(收到 npm WARN enoent ENOENT)
  4. 编辑 package.json,添加 "azure-mobile-apps-client": "^2.0.0-rc1"
  5. 在 app 文件夹中,创建新文件 declarations.d.ts。
  6. 已添加
    声明模块“azure-mobile-apps-client”; 到 declarations.d.ts(部署仍然显示主页)
  7. 编辑了 home.ts,添加了
    从“azure-mobile-apps-client”导入 azureMobileClient; 在从“离子角度”导入 {NavController} 下; (项目部署但显示 空白屏幕)

包.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"
  }
}

声明.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);
  }
}

【问题讨论】:

  • 您遇到过这个问题吗?
  • @RandikaRatnayake 我走得更远,但仍然无法连接 Azure。我手动添加了所有包,因为存在某种加载问题。我还必须手动添加一个 Azure 类型,然后加载页面,但是一旦我实际调用了任何 Azure 方法,我就会得到一个实例化错误。我尝试同时使用应用程序级别和页面级别的 Azure 对象声明,但无济于事。非常令人沮丧。我能够进行正常的网络通话,但不能进行 Azure。我已经两个月没玩过了。如果您有任何见解,我将不胜感激。
  • 我还在努力,会及时通知你。

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


【解决方案1】:

除了引入它之外,您实际上并没有在代码中使用 azureMobileClient。ENOENT 表示它没有被下载。你需要一个成功的 npm install 才能使用它。然后你实际上需要使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 2020-03-27
    • 2013-12-03
    • 2022-01-21
    • 2017-03-21
    • 2019-04-13
    相关资源
    最近更新 更多