我已将以下代码从 Ionic 3 迁移到 Ionic 5
const alert = await this.alertCtrl.create({
subHeader: "About" + " <b>" + this.user.name + "</b>",
message: "Test Messgae",
buttons: [
{
text: 'Close',
role: 'cancel',
handler: () => {
}
}
]
});
await alert.present();
Run Code Online (Sandbox Code Playgroud)
在 Ionic 3 中,用户名以粗体显示,但在 Ionic 5 中,HTML 标签不起作用,< b > 标签显示为文本。请建议我如何在 IONIC 5 中设置警报中的文本样式。
我正在将我的项目从 Ionc3 迁移到 Ionic5。我有一个 ion-textarea ,它会随着用户键入而增加高度,并且它在 Ionic3 中工作。以下是代码。
HTML 页面:
<ion-textarea #hvUserPost type="text" (input)="adjustDesc()"></ion-textarea>
Run Code Online (Sandbox Code Playgroud)
TS页面:
@ViewChild('hvUserPost') hvUserPost: ElementRef;
adjustDesc() {
let textArea;
textArea = this.hvUserPost['_elementRef'].nativeElement.getElementsByClassName("text-input")[0];
textArea.style.overflow = 'hidden';
textArea.style.height = 'auto';
var scrollHeight = textArea.scrollHeight;
textArea.style.height = scrollHeight + 'px';
}
Run Code Online (Sandbox Code Playgroud)
现在在 Ionic4 中唯一改变的是以下声明
@ViewChild('hvUserPost', {static: false}) hvUserPost: ElementRef;
Run Code Online (Sandbox Code Playgroud)
在 Ionic4 中,我收到以下错误。
ERROR TypeError: Cannot read property 'nativeElement' of undefined
Run Code Online (Sandbox Code Playgroud)
所以this.hvUserPost['_elementRef']是未定义的,this.hvUserPost.nativeElement也是未定义的。
在我的 Ionic 5 应用程序中,我有以下导航路径。
PageHome -> PageA -> PageB
Run Code Online (Sandbox Code Playgroud)
我已经为 PageA 实现了 CanDeactivate 防护。
export class LeavePageGuard implements CanDeactivate<isDeactivatable>{
canDeactivate(
component: isDeactivatable
): Observable<boolean> | Promise<boolean> | boolean {
return component.canPageLeave();
}
}
Run Code Online (Sandbox Code Playgroud)
当用户编辑某些内容并在保存之前按后退按钮时,我会弹出一个弹出窗口来确认用户是否想要离开。
async canPageLeave() {
if (this.byPassNav) {
this.byPassNav = false;
return true;
}
if (JSON.stringify(this.dataOld) != JSON.stringify(this.data)) {
const alert = await this.alertCtrl.create({
header: 'Unsaved Chnages',
message: 'Do you want to leave?',
buttons: [
{
text: 'No',
role: 'cancel',
handler: () => { }
},
{
text: …Run Code Online (Sandbox Code Playgroud) 我无法在 Ionic 5 中实现 canDeactivate 防护。以下是我的代码。
模型.ts
export interface isDeactivatable {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
Run Code Online (Sandbox Code Playgroud)
离开页面.guard.ts
export class LeavePageGuard implements CanDeactivate<isDeactivatable>{
canDeactivate(
component: isDeactivatable
): Observable<boolean> | Promise<boolean> | boolean {
console.log('LeavePageGuard');
return component.canDeactivate();
}
}
Run Code Online (Sandbox Code Playgroud)
测试页.ts
export class TestPage implements OnInit, isDeactivatable{
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
console.log('canDeactivate in TestPage');
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
本地路由.Module.ts
const routes: Routes = [
{
path: '',
component: HomePage,
children:[
{
path: 'test',
loadChildren: () => …Run Code Online (Sandbox Code Playgroud) lazy-loading ionic-framework angular-route-guards candeactivate ionic5
我知道要在嵌套对象中使用Firestore FieldValue increment函数,我需要在update方法中提及完整的路径。我的 Ionic 5 项目的 main 方法采用对象字段的名称。以下是我尝试使用它的方法
updateCounter(attr: string){
Way1:
let obj = {};
obj[attr] = firebase.firestore.FieldValue.increment(1); //This is working
obj.count[attr] = firebase.firestore.FieldValue.increment(1); //This is not working. Value is always 1
this.afs.doc('path').update(obj);
Way2:
this.afs.doc('path').update({
'count.${attr}': firebase.firestore.FieldValue.increment(1); //Creating a field called '${attr}' and not replacing the value;
});
Way3:
this.afs.doc('path').update({
`count.${attr}`: firebase.firestore.FieldValue.increment(1); //Error as '``' value not accepted in the function
});
}
Run Code Online (Sandbox Code Playgroud) 我的项目使用 Ionic 5,刚刚升级到 Capacitor 3。升级后,我收到以下错误。
Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.
Run Code Online (Sandbox Code Playgroud)
因此,根据不同论坛建议的解决方案,我首先添加mavenCentral()并center()构建build.gradle项目。这是成功的。然后我删除了jcenter(). 在此构建之后,我收到以下错误。
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find org.apache.cordova:framework:7.0.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/apache/cordova/framework/7.0.0/framework-7.0.0.pom
- https://repo.maven.apache.org/maven2/org/apache/cordova/framework/7.0.0/framework-7.0.0.pom
- file:/Users/**/android/capacitor-cordova-android-plugins/src/main/libs/framework-7.0.0.jar
- file:/Users/**/android/capacitor-cordova-android-plugins/src/main/libs/framework.jar
- file:/Users/**/android/app/libs/framework-7.0.0.jar
- file:/Users/**/android/app/libs/framework.jar
Required by:
project :app > project :capacitor-android
project :app > …Run Code Online (Sandbox Code Playgroud) ionic5 ×4
html ×2
alert ×1
android ×1
angular ×1
capacitor ×1
elementref ×1
gradle ×1
javascript ×1
jcenter ×1
lazy-loading ×1
routes ×1