标签: ionic3

Promise 重试,直到使用 Typescript 成功/失败

我的移动应用程序会连续将多个文件上传到服务器,这些文件通常来自连接强度存在问题的偏远地区。为此,我想尝试几次发送文件。我还想在失败时继续尝试下一个,导出结束时显示所有错误消息(即“已上传 10 个文件,3 个失败...”)

但是,我无法弄清楚带有承诺的递归重试模式。这是我到目前为止所拥有的:

sendFile(params, retries = 3){
    console.log("SENDING FILE: ", retries, "attempts remaining", params)

    return new Promise((resolve, reject)=>{
      if(retries > 0){
        this._sendFile(params)
        .then(()=>{
          // Upload Success
          console.log("Upload Success!")
          resolve()
        })
        .catch((err)=>{
          console.log("Upload Fail", err)
          // Retry
          this.sendFile(params, --retries)
        })
      }else{
        console.log("Failed 3 times!!!")
        //Record error
        this.exportStatus.errors.push({
          message:"A file failed to upload after 3 attempts.",
          params: params
        })

        //Resolve and move on to next export
        resolve()

      }
    })

  }

  _sendFile(params){

      // Mobile - File Transfer

        let options = { …
Run Code Online (Sandbox Code Playgroud)

javascript typescript ionic-framework es6-promise ionic3

5
推荐指数
1
解决办法
1万
查看次数

Ionic 3如何使用withCredentials在请求后保存cookie

我必须在 Ionic 3 应用程序中的 API 响应后保存 cookie,但我无法执行此操作,我需要您的帮助。

我在请求之前创建一个拦截器并在所有结果“withCredentials = true”上进行设置,但这不起作用,您是否有其他资源可以执行此操作?按照我下面的代码操作

private getRequestOptionArgs(options?: RequestOptionsArgs) : RequestOptionsArgs {

    if (options == null) {
        options = new RequestOptions({ withCredentials: true });
    }
    if (options.headers == null) {
        options.headers = new Headers();
    }

    options.headers.append('Content-Type', 'application/json');
    options.headers.append('Access-Control-Allow-Credentials', 'true');
    options.headers.append('Access-Control-Allow-Origin', '*');

    options.withCredentials = true

    return options;
}
Run Code Online (Sandbox Code Playgroud)

cookies http ionic3

5
推荐指数
0
解决办法
811
查看次数

如何禁用 Ionic 3 中的模态动画?

我在旧系统上运行我的 Ionic 应用程序,该系统不能很好地处理动画,因此我尝试禁用它们。

我尝试opts在创建模态时设置为:

{
    cssClass: 'plain-modal',
    enableBackdropDismiss: false,
    enterAnimation: 'no-animation',
    leaveAnimation: 'no-animation',
    showBackdrop: true
}
Run Code Online (Sandbox Code Playgroud)

似乎no-animation在这里没有效果。它实际上并不应用于任何 DOM 元素。或者是吗?

在诊断时,我注意到 Ionic.content在模态即将打开或关闭时应用内联 CSS:

transform: translateX(100%);
will-change: transform, -webkit-transform;
transition-duration: 500ms;
transition-timing-function: cubic-bezier(0.36, 0.66, 0.04, 1);
Run Code Online (Sandbox Code Playgroud)

所以我尝试使用以下方法覆盖那些initial !important:

.show-page.plain-modal {
    > ion-backdrop {
        opacity: 0.5; // Nothing is displayed if I don't do this
    }

    > .modal-wrapper {
        opacity: 1; // Again nothing is displayed if I don't do this

        > .ion-page { …
Run Code Online (Sandbox Code Playgroud)

typescript ionic-framework ionic3 angular

5
推荐指数
1
解决办法
3039
查看次数

Angular4 - 如何交错可观察数组的动画

我正在尝试对 Angular4 中的一系列可观察对象执行交错动画,这是我的代码:

  animations: [
    trigger('fade', [
      transition(':enter', [style({opacity: 0}), animate('2s ease')])
    ]),
    trigger('stagger', [
      transition(':enter', [
        query(
          ':enter', 
          stagger(
            '0.5s', 
            [animateChild()]
          ),
          { optional: true }
        )
      ])
    ])
  ], 

export class TimetablePage {
  classes: Observable<ClassTime[]>;
Run Code Online (Sandbox Code Playgroud)

还有我的模板:

  <ion-list [@stagger]>
    <timetable-item 
    *ngFor="let class of classes | async | sort: 'time'" 
    [class]="class"
    [@fade]>
    </timetable-item>
  </ion-list>
Run Code Online (Sandbox Code Playgroud)

淡入淡出动画正在运行,但动画未交错。

animation ionic3 angular

5
推荐指数
0
解决办法
326
查看次数

后台应用程序中的 Ionic 3 本地通知

如何在 Ionic 3 的后台应用程序中创建本地通知?我在这里尝试了教程https://ionicframework.com/docs/native/local-notifications/但它仅适用于前台应用程序

提前致谢..

ionic-framework ionic-native ionic3

5
推荐指数
1
解决办法
3377
查看次数

如何在 typescript / Angular 中设置子 html 元素的样式

我正在使用 ionic 3 构建混合移动应用程序,要求之一是用户能够动态更改工具栏颜色。页面渲染后,html 如下所示:

<div id="divICanControl"> //this div i can control <div> //but this one is generated by the framework and this is the div that change the background color of the toolbar </div> </div>

我尝试执行以下操作: document.getElementById('divICanControl').childNodes[0].style.backgroundColor = this.someColor;

它偶尔可以工作,但它在 vscode 中创建了以下错误: [ts] Property 'style' does not exist on type 'Node'.

它停止了应用程序的构建。

我现在正在寻找使用角度操纵 dom 的正确方法。

感谢您的帮助,请记住我是 Angular 5 和 TypeScript 的新手。

dom typescript visual-studio-code ionic3 angular

5
推荐指数
1
解决办法
2万
查看次数

带左/右箭头的滑块

您能告诉我如何为 Ionic 滑块组件创建右/左箭头吗?

演示: Stackblitz

注:请查看home.html页面

在此输入图像描述

.html

<ion-slides  [pager]="true" [slidesPerView]="2">
        <ion-slide>
            <h1>Slide 1</h1>
        </ion-slide>
        <ion-slide>
            <h1>Slide 2</h1>
        </ion-slide>
        <ion-slide>
            <h1>Slide 3</h1>
        </ion-slide>
    </ion-slides>
Run Code Online (Sandbox Code Playgroud)

css typescript ionic3 angular swiper.js

5
推荐指数
1
解决办法
2万
查看次数

仅获取 ionic 3 格式的日期 2018-02-28

我正在最新版本的 Angular 中使用当前的 Date() 函数。我的理解完全正确。但我得到的日期和时间如下所示:

   today = new Date().toISOString();
   console date: 2018-02-08T09:07:15.146
Run Code Online (Sandbox Code Playgroud)

我只想要2018-02-08。

你们能帮我如何只获取上述格式的日期,而不包含时间。

谢谢。

typescript ionic3 angular

5
推荐指数
1
解决办法
1万
查看次数

错误:deleted_client OAuth 客户端已删除

如何删除旧的 clientID?

我已经在谷歌开发者控制台中创建并生成了一个新的 clientID

谷歌开发者控制台

新的 clientID 与浏览器中的 clientID 不匹配。这可能解释了尝试登录时出现的错误

尝试登录时出错

我知道应用程序设置中一切正常

  • 这是我的package.json

    “名称”:“auth-firebase-2”,“版本”:“0.0.1”,“作者”:“Ionic Framework”,“主页”:“ http://ionicframework.com/ ”,“私人”: true, "scripts": { "clean": "ionic-app-scripts clean", "build": "ionic-app-scripts build", "lint": "ionic-app-scripts lint", "ionic:build ": "ionic-app-scripts build", "ionic:serve": "ionic-app-scriptsserve" }, "dependency": { "@angular/animations": "5.2.9", "@angular/common “:“5.2.9”,“@角/编译器”:“5.2.9”,“@角/编译器-cli”:“5.2.9”,“@角/核心”:“5.2.9”,“ @角/形式":"5.2.9","@角/http":"5.2.9","@角/平台浏览器":"5.2.9","@角/平台浏览器动态" :“5.2.9”,“@ionic-native/core”:“4.6.0”,“@ionic-native/splash-screen”:“4.6.0”,“@ionic-native/status-bar”: “4.6.0”,“@ionic/storage”:“2.1.3”,“angularfire2”:“^ 5.0.0-rc.6.0”,“cordova-android”:“7.0.0”,“cordova-浏览器” ": "5.0.3", "cordova-ios": "4.5.4", "cordova-plugin-device": "^2.0.2", "cordova-plugin-googleplus": "^5.3.0", “cordova-plugin-ionic-keyboard”:“^2.0.5”,“cordova-plugin-ionic-webview”:“^1.2.0”,“cordova-plugin-splashscreen”:“^5.0.2”,“ cordova-plugin-whitelist":"^1.3.3","f​​irebase":"^4.13.0","ionic-Angular":"3.9.2","ionicons":"3.0.0","rxjs" :“5.5.8”,“sw-toolbox”:“3.6.0”,“zone.js”:“0.8.26”},“devDependency”:{“@ionic/app-scripts”:“3.1.9 ", "typescript": "~2.6.2" }, "description": "一个 Ionic 项目", "cordova": { "plugins": { "cordova-plugin-whitelist": {}, "cordova-plugin-设备": {}, "cordova-plugin-splashscreen": {}, "cordova-plugin-ionic-webview": {}, "cordova-plugin-ionic-keyboard": {}, "cordova-plugin-googleplus" : …

cordova-plugins google-signin ionic3

5
推荐指数
1
解决办法
2万
查看次数

core 2.1 signalR 连接成功但客户端为空

我正在尝试在新的 dotnet core2.1 中使用 signalR。我已经设置了 C# 服务器和 ionic 3 应用程序作为客户端。我已经在它们之间建立了成功的网络套接字连接。当我尝试使用从服务器到客户端的 SendAsync 时,即使建立了成功的连接,客户端也显示为 null。
我已经做了一些测试,甚至尝试使用 OnConnectedAsync 覆盖来查看发生了什么。它确实触发了,但 context.user.identity.name 为空,并且客户端仍然为空。

在浏览器日志中:

Information: WebSocket connected to ws://localhost:xxxx/myHub
Run Code Online (Sandbox Code Playgroud)

在我的中心

public async Task Send(string message)
{
  await Clients.All.SendAsync("SendMessage", message);
}
Run Code Online (Sandbox Code Playgroud)

在控制器中

    public async Task<IActionResult> NewBuild()
{
  await myHub.Send("New Build Completed.");
  return Ok();
}
Run Code Online (Sandbox Code Playgroud)

在我的创业公司中

services.AddCors(options => options.AddPolicy("CorsPolicy",
        builder =>
        {
          builder.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin().AllowCredentials();
        }));

  services.AddSignalR();

app.UseCors("CorsPolicy");

  app.UseSignalR(routes =>
  {
    routes.MapHub<myHub>("myHub");
  });
Run Code Online (Sandbox Code Playgroud)

并在离子中

 hubConnection: HubConnection;
this.hubConnection =  new HubConnection('http://localhost:xxxx/myHub', {
  transport: TransportType.WebSockets
});
this.hubConnection.on("SendMessage", () => {
  this.InitTodayBuilds(); …
Run Code Online (Sandbox Code Playgroud)

c# signalr ionic3

5
推荐指数
1
解决办法
4761
查看次数