Node.js 如何在angularv8中显示来自服务器的数据
我想显示登录应用程序的人的姓名。我试过这个Node.js 如何在angularv8中显示来自服务器的数据,node.js,oracle11g,ionic4,angular8,Node.js,Oracle11g,Ionic4,Angular8,我想显示登录应用程序的人的姓名。我试过这个 getprotected() { return this.http.get(${this.url}/api/protected_things) .pipe( catchError(e => { let status = e.status; if (status === 401) { this.showAlert('You are not authorized
getprotected() {
return this.http.get(${this.url}/api/protected_things)
.pipe(
catchError(e => {
let status = e.status;
if (status === 401) {
this.showAlert('You are not authorized for this!');
this.logout();
}
throw new Error(e);
})
)
}
表1.ts
tab1.html
但它不起作用。
谢谢您应该尝试使用res.name访问所需的数据 作为一般的经验法则,尝试记录您的结果。 .subscribe中的一个简单的console.logres将帮助您可视化接收的对象 如果问题提前发生,chrome network inspector将帮助您检测收到的数据。请记住,空对象不会触发捕获错误。要了解有关chrome中“网络”选项卡的更多信息,请执行以下操作:
顺便说一句,你应该看一些教程,在youutbe上你可以找到很棒的材料谢谢你,但是没有任何东西显示出来。我是新来的,你能给我举个例子吗?事实上,我对我的答案投了反对票,你真是太客气了。您必须粘贴authService.getprotected的代码,这样我才能看到它。对不起,是吗?我的道歉GetProtected{返回this.http.get${this.url}/api/protected_things.pipe catchErrore=>{let status=e.status;if status==401{this.showAlert'您没有此权限!';this.logout;}抛出新错误;}
export class Tab1Page implements OnInit {
data = '';
constructor(private authService: AuthService, private storage: Storage, private toastController: ToastController, private http: HttpClient) { }
ngOnInit() {
this.authService.getprotected().subscribe(res => {
this.data = res['name'];
});
}
<p class="ion-text-center">Bienvenu</p>
<p class="ion-text-center"><b>{{ data }}</b></p>
<ion-button expand="full" (click)="logout()">Deconnecte Toi</ion-button>