我有一个要处理的对象列表。该对象被传递给一个承诺函数,该函数执行此操作并解析返回。根据先前缓存的值,该过程可能是即时的,也可能不是。如果已经有计算值,它会立即解析到它。否则,它会计算。现在我遇到的问题是在计算第一个对象的状态之前将下一个对象传递给承诺:
let people = [
{groupId: 1, name: 'Jessica Coleman', status: 'Unknown', id:1}
{groupId: 1, name: 'Eric Tomson', status: 'Unknown', id:2}
{groupId: 1, name: 'Samuel Bell', status: 'Unknown', id:3}
];
Run Code Online (Sandbox Code Playgroud)
现在我想绝对等待承诺在循环期间解决,即使承诺需要一分钟来计算实例。同一组中的所有人员都具有相同的状态。因此,promise 检查是否已经计算了一个组。如果是,则返回它。否则,它会计算。这就是问题所在。杰西卡1号还没说完,其他人就通过了。
people.map(function(person) {
// return the promise to array
this.calculatorService
.getStatus(person)
.then(function(res) {
person.status = res;
});
});
Run Code Online (Sandbox Code Playgroud) 我曾尝试向服务器发送 POST 数据,但收到错误“net::ERR_CERT_INVALID”。如下所示的代码是我试图绕过错误但它仍然失败的代码。请帮忙指教。谢谢你。
import { HttpClient, HttpParams } from '@angular/common/http';
createData(data): Promise<any> {
let post_message = data;
let header_node = {
Accept: 'application/json',
rejectUnauthorized: 'false',
}
// this.oauth_header.Authorization = 'Bearer ' + access_token;
const url_params = new HttpParams()
.set('rejectUnauthorized', 'false')
.set('requestCert', 'false')
.set('insecure', 'true')
return this.http.post('https://ip/createdata', post_message, {
headers: header_node,
}).toPromise();
Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android用于录制通话的应用.这是我的代码片段.
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setOutputFile(file_path);
Run Code Online (Sandbox Code Playgroud)
这对于android 7 以下的设备非常有效,但是当我使用Android 7移动设备时,我只能听到外出的声音,但听不到传入的声音.
任何人都可以帮我解决它吗?
我是ionic3的新手,我有2页,一个是列表页面,有上市,我从Rest API获取该列表,当我点击该列表中的特定项目,那时我想获得该页面的详细信息,但是当我点击特定项目时我收到错误:ListDetailsPage is part of the declaration of 2 modules, Please consider moving ListDetailsPage to a higher module that imports AppModule and ListDetailsPageModule,有谁可以请帮助我为什么我收到此错误?在这里,我添加了我的所有代码,
1)app.module.ts
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { ListDetailsPage …Run Code Online (Sandbox Code Playgroud) 我正在使用HTTP POST方法下载文件。我想调用另一种方法来向最终用户显示下载进度,直到文件下载完成。如何使用reportProgress在HttpClient此。
downfile(file: any): Observable<any> {
return this.http.post(this.url , app, {
responseType: "blob", reportProgress: true, headers: new HttpHeaders(
{ 'Content-Type': 'application/json' },
)
});
}
Run Code Online (Sandbox Code Playgroud) 在我的 Ionic3 应用程序中,我计算文件大小如下。
HTML
<div>
<input type="file" accept="*" (change)="onSelect($event)">
<button ion-button (click)="calcSize()">calculate size</button>
</div>
<p>Size: {{ size }}</p>
Run Code Online (Sandbox Code Playgroud)
TS
file: File;
size: number;
onSelect(event: any) {
this.file = event.target.files[0];
}
calcSize() {
this.size = this.file.size;
}
Run Code Online (Sandbox Code Playgroud)
以上代码在 iOS 13.2 以下的所有 Android 设备和 iOS 设备上都能完美运行。
但是在 iOS 设备上从照片库中选择大于 13.2 的size视频时,只有视频文件的值为 0。
但是当从 iCloud Drive 选择视频时效果很好。
任何帮助都受到高度赞赏。
在StackBlitz上查找问题。
我有一个 Ionic 4 项目,我需要在其中发布并调用服务器。该服务器是一个 Spring Java 服务器,它只允许来自http://localhost:4200 的调用并在http://localhost:8080上运行自己。我只有服务器的 DNS 地址。问题是当我为移动设备部署应用程序时,它会启动一个本地服务器,其中 CORS 由WebView强制执行。
我收到此错误:
对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost:4200 '。
对于我使用HttpClient来自 Angular的 Rest Call ,我已经读到 Ionic-Native/HTTP 处理 CORS 问题,但我需要重写我的所有调用,而且我无法在浏览器上测试它,这需要相当长的时间发展的时间。是否可以使用代理来处理此问题,该代理告诉服务器我的来源是“ http://localhost:4200 ”,或者在 Spring 上允许来自特定端口的任何 IP 地址?我还看到有一个名为ionic-native-http-connection-backend 的库,它在可能的情况下使用来自 ionic 的本机 http,但它不起作用。
我希望有一种方法可以使用HttpClientfrom Angular 并以某种方式解决此问题,或者是否必须在后端进行更改以使它们最小化。
感谢您抽出宝贵时间帮助我。
这是我的 CLI 和项目版本:
ionic (Ionic CLI) : 4.2.1 (C:\Users\John\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.0.0-beta.12
@angular-devkit/build-angular : 0.7.5
@angular-devkit/schematics : 0.7.5
@angular/cli : 6.1.5
@ionic/angular-toolkit : 1.0.0
Run Code Online (Sandbox Code Playgroud)
科尔多瓦:
cordova …Run Code Online (Sandbox Code Playgroud) 我不明白为什么我一次又一次地出现这个错误......当我有一个新的提供者时。当我有任何其他提供商(如地理定位等)时,出现此错误:
错误:未捕获的错误:NgModule 'AppModule' 的提供程序无效 - 仅允许提供程序和类型的实例,得到:[StatusBar, SplashScreen,?[object Object]?, ...]
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { ImagePicker } from '@ionic-native/image-picker';
import { Crop } from '@ionic-native/crop';
import { AuthService } from '../pages/core/auth.service';
import { UserService } from '../pages/core/user.service';
import { FollowService } from "../pages/core/follow.service";
import { AngularFireModule } from 'angularfire2';
import { …Run Code Online (Sandbox Code Playgroud) 我想提供一个选项,允许用户ion-select在选择后决定不选择某个选项时清除表单字段,但我很难找到任何可以提供帮助的内容。
<ion-item class="formField ionField">
<ion-label color="primary" stacked>PROJECT</ion-label>
<ion-select
#projectName
ngModel
name="project"
interface="action-sheet">
<ion-option (ionSelect)="projectSelect(project.ProjectName,i)" [value]={ID:project.ID,Name:project.ProjectName} *ngFor="let project of projectArray; let i = index" >{{project.ProjectName}}</ion-option>
</ion-select>
</ion-item>Run Code Online (Sandbox Code Playgroud)
<ion-option (ionChange)="resetValue()">Reset</ion-option>
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。
如果 itemNew.UL_DATA 和 itemNew.LL_DATA 等于 0 或“”,如何将输入限制为仅具有 2 位小数的数字。
<ion-col col-2>
<input (keypress)="ShowKey();"
[style.display]="itemNew.UL_DATA=='0' && itemNew.LL_DATA=='0'?'none':'inherit'"
style="width: 100%;flex-grow: 1; align-self: flex-end;"
type="text" placeholder="Actual After Value"
[(ngModel)]="itemNew.ACTUAL_VALUE_L"
name="ActualData"
id="ActualData">
</ion-col>
Run Code Online (Sandbox Code Playgroud) 我的表格快准备好了。现在我只需要制作一个包含内容的模式窗口,它应该通过单击子组件内部的按钮弹出打开。另一方面,模态是父组件的一部分。我需要让他们相互沟通,以便通知家长,按钮已被单击,现在是时候打开模式了。我发出一个布尔事件,它等于单击按钮的状态,但我没有从父级得到任何反应,尽管我有一个可从外部绑定的属性(@Input())如何实现这样的任务?我哪里弄错了?
子组件方法
onReset() {
this.formResetClicked = !this.formResetClicked;
this.formReseted.emit(this.formResetClicked); }
Run Code Online (Sandbox Code Playgroud)
父级的 HTML
<div class="container">
<div class="wrapper">
<div class="slider">
<app-form-slider class="slider-app"></app-form-slider>
</div>
<div class="form" (formReseted)="clickedState = $event">
<router-outlet></router-outlet>
</div>
<div class="modal" [ngStyle]="{display: clickedState ? 'block' : 'none'}">
<div class="modal__content">
<div class="modal__content--header">
<span>×</span>
<p>WARNING!</p>
</div>
<div class="modal__content--text">
<p>If you click 'continue' the all information will be deleted. <br>Close this window if you don't want this to happen.</p>
</div>
<div class="modal__content--button">
<button>Continue</button>
</div>
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
父母的财产
export class AppComponent { …Run Code Online (Sandbox Code Playgroud) 我想知道当我们在 ionic 3 中默认单击 ion-navbar 后退按钮时调用哪个函数。我想在硬件后退按钮单击时调用相同的函数。
我正处于迁移到 Angular 7 的第一周,我一直在使用基于模板的基本验证在我的项目中制作基本表单,但我现在需要根据一个字段的值必须高于其他
我已经尝试在组件控制器中使用这些值本身,但是虽然我能够确认这些值是否有效,但我无法使用此代码向用户显示问题所在
if (issueThresholdForm.value.lowScore > issueThresholdForm.value.highScore) {
// Show user error
// This is the messing part, I guess
}
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的模板
<div *ngIf="_issueCategory">
<form (submit)="submitIssueThreshold(issueThresholdForm)" #issueThresholdForm="ngForm">
<mat-form-field class="half-width" floatLabel="always">
<mat-label [translate]="'issueThreshold.modals.highScore'"></mat-label>
<input name="highScore" type="number" matInput placeholder="0" [(ngModel)]="_issueCategory.highScore"
required #highScore="ngModel">
</mat-form-field>
<mat-form-field class="half-width" floatLabel="always">
<mat-label [translate]="'issueThreshold.modals.lowScore'"></mat-label>
<input name="lowScore" type="number" matInput placeholder="0" [(ngModel)]="_issueCategory.lowScore"
required #lowScore="ngModel">
</mat-form-field>
<mat-form-field class="full-width" floatLabel="always">
<mat-label [translate]="'issueThreshold.modals.description'"></mat-label>
<textarea name="description" matInput [(ngModel)]="_issueCategory.thresholdDescription">
</textarea>
</mat-form-field>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" [translate]="'modal-confirm.cancel'"></button>
<button type="submit" class="btn btn-primary …Run Code Online (Sandbox Code Playgroud) angular ×10
ionic3 ×6
typescript ×4
httpclient ×2
javascript ×2
android ×1
angular7 ×1
back ×1
button ×1
components ×1
cors ×1
eventemitter ×1
forms ×1
http ×1
ion-select ×1
ionic2 ×1
ios ×1
ios13.2 ×1
mobile ×1