我正在使用 Angular 4/Ionic 3 构建一个应用程序,加载用户从服务器上传的图像。我目前正在使用下面的代码,但它不起作用:
<img src="{{user.image}} || assets/images/profileimage.png" />
Run Code Online (Sandbox Code Playgroud)
我不确定我做错了什么。我想在主图像从服务器加载之前它会显示占位符图像。相反,在主图像加载之前它仍然是空白的。我应该使用 Angular 特有的东西吗?
我的移动应用程序会连续将多个文件上传到服务器,这些文件通常来自连接强度存在问题的偏远地区。为此,我想尝试几次发送文件。我还想在失败时继续尝试下一个,导出结束时显示所有错误消息(即“已上传 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) 我必须在 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) 按照 Firebase 教程实现 Firebase 托管。在控制台中托管应用程序。但问题是当我更改了 html 模板并通过运行在 Firebase 控制台中重新部署时
ionic build --browser
Run Code Online (Sandbox Code Playgroud)
和
firebase deploy
Run Code Online (Sandbox Code Playgroud)
它正在部署,但未在移动浏览器中更新。
例如,我创建了一个离子和角度演示项目。使用 InAppBrowser 可以连接 Firebase url
this.iab.create('https://xxx-xxxx.firebaseapp.com','_blank',"location=no,clearsessioncache=yes,clearcache=yes");
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在应用程序设置中清除应用程序缓存时。然后我得到输出
上面带有更新文本的图像。上传到 firebase 后的预期结果。
下面的片段试图限制缓存。
1. clearsessioncache=yes,clearcache=yes given in InAppBrowser
Run Code Online (Sandbox Code Playgroud)
2.在Firebase.json
"headers": [ {
"source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
"headers" : [ {
"key" : "Access-Control-Allow-Origin",
"value" : "*"
} ]
}, {
"source" : "**/*.@(jpg|jpeg|gif|png)",
"headers" : [ {
"key" : "Cache-Control",
"value" : "max-age=7200"
} ]
}, {
"source" : "404.html",
"headers" : [ { …Run Code Online (Sandbox Code Playgroud) 我在旧系统上运行我的 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) 如何在 Ionic 3 PWA 中定义可选参数?
我当前的@IonicPage装饰器看起来像:
@IonicPage({
segment: "landing/:id"
})
Run Code Online (Sandbox Code Playgroud)
但id参数必须是可选的。如果我没有通过id,我会收到此错误:
未捕获(承诺):要插入的无效视图
怎么做?
提前致谢!
我遵循了官方文档,我的代码如下:
let alert = this.alertCtrl.create({
title: 'Alert',
subTitle: 'Subtitle',
message: 'This is an alert message.',
buttons: ['OK'],
cssClass: 'profalert'
});
alert.present();
Run Code Online (Sandbox Code Playgroud)
和我的 CSS:
.profalert{
color:#e7333c;
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)
但这并没有改变警报框的颜色。我也试过alert .setCssClass('profalert');
我已经检查过这个
我有一个 ionic3 项目,我正在尝试在 iphone plus 8、12.4 模拟器上运行它。但是,当我运行时:
ionic cordova emulate ios --target="iPhone-8-Plus" --verbose
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误:
** BUILD SUCCEEDED **
Command finished with error code 0: xcodebuild -workspace,MyApp.xcworkspace,-scheme,MyApp,-configuration,Debug,-sdk,iphonesimulator,-destination,platform=iOS Simulator,name=iPhone 8 Plus,build,CONFIGURATION_BUILD_DIR=/Users/myuser/MyProjects/mobileapp/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/myuser/MyProjects/mobileapp/platforms/ios/build/sharedpch,-UseModernBuildSystem=0
No scripts found for hook "after_compile".
No scripts found for hook "after_build".
> native-run ios --app "platforms/ios/build/emulator/MyApp.app" --target iPhone-8-Plus --verbose
[native-run] 2019-08-08T10:01:24.916Z client:usbmuxd connectUsbmuxdSocket
[native-run] 2019-08-08T10:01:24.919Z client:usbmuxd getDevices
[native-run] 2019-08-08T10:01:24.920Z protocol:usbmux socket write: {"messageType":"ListDevices"}
[native-run] 2019-08-08T10:01:25.517Z protocol:usbmux Response: {"DeviceList":[]}
[native-run] 2019-08-08T10:01:25.523Z native-run Caught fatal error: { Error: No device or simulator …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上查找问题。
我真的需要一些帮助来配置 karma.conf.js 以处理打字稿文件,或者不确定缺少什么或我在这里做错了什么。非常新的单元测试并学习了 Jasmine 框架(在示例中它使用 *.js 和 *.spec.js 文件)但在我的 ionic-angular 项目中它的 *.ts 文件和获取错误(如下所示)。我一直试图弄清楚2天,但无法解决这个问题。任何帮助真的很感激。
[在 Angular 6 (6.1.10) 和 typescript (3.8.+.) 中使用 ionic 3 (ionic-angular 3.9.+) 框架]
我的 tsconfig.json >
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es6"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/**/*.spec.ts",
"src/**/__tests__/*.ts"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
Run Code Online (Sandbox Code Playgroud)
我的 karma.conf.js >
module.exports = function (config) { …Run Code Online (Sandbox Code Playgroud) ionic3 ×10
angular ×7
typescript ×5
javascript ×2
caching ×1
cookies ×1
cordova ×1
es6-promise ×1
firebase ×1
html ×1
http ×1
ionic2 ×1
ios ×1
ios13.2 ×1
iphone ×1
unit-testing ×1