我有一个 auth 守卫,需要运行一个 api 调用来查看他们是否可以访问。我不相信从订阅中返回数据是可能的,但我还能怎么做?
我需要获取用户 ID,然后调用 api,然后根据 api 调用返回 true 或 false。
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from 'src/app/services/auth.service';
@Injectable({
providedIn: 'root'
})
export class TeamcheckGuard implements CanActivate {
success: boolean;
constructor(
private router: Router,
private authService: AuthService
) {}
// Checks to see if they are on a team for the current game they selected.
canActivate(next: ActivatedRouteSnapshot,state: RouterStateSnapshot): …Run Code Online (Sandbox Code Playgroud) 运行 $ ionic cordova build android 时,构建失败。
尝试安装 npm 插件 cordova-android-support-gradle-release 但遇到了这个问题:https : //github.com/dpa99c/cordova-android-support-gradle-release/issues/42
实际上,我没有为此编写特定的代码。
FAILURE:构建失败,出现异常。
com.android.build.api.transform.TransformException:java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:合并 dex 档案时出错:了解如何在https:/ /developer.android.com/studio/build/dependencies#duplicate_classes。程序类型已经存在:org.apache.cordova.BuildHelper
我正在尝试使用 ionic4 应用程序中的以下代码捕获错误代码为 400 的 HTTP 错误。但它没有抓住它,这里有什么问题。控制台日志行均未执行,但在 Firefox 控制台中显示 400 错误。
export class AuthService {
constructor(private httpClient: HttpClient) {}
login(email: string, password: string){
const data = {
password: password,
email: email,
}
this.httpClient.post(url, data).pipe(
tap((res: IAuthResponse) => {
console.log("Catch error 1")
return res;
}),
catchError((error) => {
console.log("Catch error 2")
return Observable.throw(new Error(error.status));
})
).subscribe(
(result) => {
console.log("Catch error 3")
},
(error) => {
console.log("Catch error 4")
}
);
}
Run Code Online (Sandbox Code Playgroud)
实际上我只想在我编码 console.log 行的任何地方处理这个错误。找到了很多这样的例子,但没有一个有效。
编辑:在我的真实代码中,控制台日志第 1 行位于 AuthService 类中,但订阅代码位于不同的类文件中。这两个类都必须根据结果进行一些初始化。所以我需要同时拥有管道代码和订阅代码。
我正在使用 ionic 5.0.0,我必须为我的登录屏幕实现加载。为此,我使用 LoadingController 完成了一些实现。但不幸的是,我收到以下错误。请看一下。
ERROR TypeError: Cannot read property 'dismiss' of undefined
at LoginPage.push../src/app/login/login.page.ts.LoginPage.dismissLoader (login.page.ts:161)
at LoginPage.push../src/app/login/login.page.ts.LoginPage.doLogin (login.page.ts:103)
at Object.eval [as handleEvent] (LoginPage.html:8)
at handleEvent (core.js:23107)
at callWithDebugContext (core.js:24177)
at Object.debugHandleEvent [as handleEvent] (core.js:23904)
at dispatchEvent (core.js:20556)
at core.js:22046
at SafeSubscriber.schedulerFn [as _next] (core.js:13527)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:192)
Run Code Online (Sandbox Code Playgroud)
当我调用this.dismissLoader();时出现此错误;这是我的 login.page.ts
import { Component, OnInit } from '@angular/core';
import { LoadingController } from '@ionic/angular';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit …Run Code Online (Sandbox Code Playgroud) 我想以弹出模式以编程方式打开 ionSelect。
@ViewChild('selectNotificationList') selectNotificationList: IonSelect;
Run Code Online (Sandbox Code Playgroud)
打开离子选择的方法是:
clickNotificationNumber() {
this.selectNotificationList.interface = 'popover';
this.selectNotificationList.open();
}
Run Code Online (Sandbox Code Playgroud)
HTML是:
<ion-card slot="end" class="langCard">
<ion-card-content>
<ion-select interface ="popover" (ionChange)="readNotification($event)" #selectNotificationList>
<ion-select-option *ngFor="let message of notificationList let notificationIndex = index" value="{{message.id}}">
{{message.notificationOptions.body}}</ion-select-option>
</ion-select>
</ion-card-content>
</ion-card>
Run Code Online (Sandbox Code Playgroud) 我有一个放置在模态中的表单,它应该在用户单击按钮时打开,但是一旦用户加载页面,它就会自动打开。
我已将我的模态导入到我的页面module.ts文件中,它使模态自动打开。如果我从模块页面中删除它,那么我会收到此错误:
ERROR Error: Uncaught (in promise): Error: No component factory found for ContactSupplierPage. Did you add it to @NgModule.entryComponents?
Error: No component factory found for ContactSupplierPage. Did you add it to @NgModule.entryComponents?
Run Code Online (Sandbox Code Playgroud)
所以现在的问题是:
list-detail.module.ts (suppose to have modal in it)
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import …Run Code Online (Sandbox Code Playgroud) 我有一个包含ion-slides元素的模式。在主页中,我有(click)使用滑块打开模态的图像的缩略图。我需要让滑块slideTo选择缩略图的索引,但还没有让它工作。
我已经完成将正确的索引传递给模态并验证它记录到控制台。在ionic 4 docs 中,我们被定向到swiper docs,在那里可以看到该slideTo方法存在,但是当滑块由 ionic 初始化时,我不知道如何使用它。我按照教程让模态和滑块运行,除了在右侧幻灯片上打开滑块外,一切都很好。我尝试了很多方法来遵循 swiper 文档。此外,滑块的缩略图数组和图像数组是相同的,因此索引匹配。
这里是模态/滑块的 ts 文件:
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { NavParams, ModalController } from '@ionic/angular';
@Component({
selector: 'app-zoom-modal',
templateUrl: './zoom-modal.component.html',
styleUrls: ['./zoom-modal.component.scss'],
})
export class ZoomModalComponent implements OnInit {
images: any;
index: number;
img: any;
@ViewChild('slider', { static: false })slider: ElementRef;
sliderOpts = {
zoom: {
maxRatio: 3,
},
slideTo: this.index // …Run Code Online (Sandbox Code Playgroud) 我想删除离子项目的点击效果。我使用了 --background-activated 和 --ripple-color 但什么也没发生。
.no-click{
--background-activated: transparent;
--ripple-color: transparent;
}
<ion-item class="no-click">
<ion-avatar slot="start">
<img [src]="img">
</ion-avatar>
<ion-label>{{name}}</ion-label>
</ion-item>
Run Code Online (Sandbox Code Playgroud)
如何消除离子项目的点击效果?
我开始研究 node js,我尝试将 ionic 应用程序与我创建的后端 nodejs 应用程序连接,但我收到此错误:
选项https://localhost:3000/insert net::ERR_SSL_PROTOCOL_ERROR
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { map } from 'rxjs/operators';
@Component({
selector: 'app-cadastro-unidade',
templateUrl: './cadastro-unidade.page.html',
styleUrls: ['./cadastro-unidade.page.scss'],
})
export class CadastroUnidadePage implements OnInit {
constructor(private http: Http) { }
ngOnInit() {
}
InsereDados(){
let data = {
};
this.http.post('https://localhost:3000/insert', data).pipe(
map(res => res.json())
).subscribe(response => {
console.log('POST Response:', response);
});
}
}
app.get('/insert', function(req, res, next) {
var uri = "xxxx" …Run Code Online (Sandbox Code Playgroud) I'm trying to do a very simple login in my Ionic 4 app. When a user logs in I set a token in storage. This is working.
I'm using an Auth Guard to check against one page in the app, so if the token is set in storage, the user can view the page. Otherwise they are redirected to the login page.
My problem is that I'm completely stuck in async hell; I just can't figure it out. I'm trying …
ionic-framework ×10
angular ×7
ionic4 ×4
javascript ×2
android ×1
cordova ×1
ion-slides ×1
ionic2 ×1
localhost ×1
node.js ×1
observable ×1
rxjs ×1
ssl ×1
swiper ×1
typescript ×1