Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 模块分析失败:关键字';私人';保留_Angular_Asp.net Core - Fatal编程技术网

Angular 模块分析失败:关键字';私人';保留

Angular 模块分析失败:关键字';私人';保留,angular,asp.net-core,Angular,Asp.net Core,我在angular 6项目中遇到如下错误: 模块分析失败:保留关键字“private”(29:12),您可以 需要适当的加载程序来处理此文件类型出口{ AuthService};|this.changemberphoto(this.currentUser.photoUrl)| 构造函数(私有、http、HttpClient);|{ } | changeMemberPhoto(photoUrl,字符串) 相关代码: import { Injectable } from '@angular/core

我在angular 6项目中遇到如下错误:

模块分析失败:保留关键字“private”(29:12),您可以 需要适当的加载程序来处理此文件类型出口{ AuthService};|this.changemberphoto(this.currentUser.photoUrl)| 构造函数(私有、http、HttpClient);|{ } | changeMemberPhoto(photoUrl,字符串)

相关代码:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {BehaviorSubject} from 'rxjs';
import {map} from 'rxjs/operators';
import {JwtHelperService} from '@auth0/angular-jwt';
import { environment } from '../../environments/environment';
import { User } from '../_models/user';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  baseUrl = environment.apiUrl + 'auth/';
  jwtHelper = new JwtHelperService();
  decodedToken: any;
  currentUser: User;
  photoUrl = new BehaviorSubject<string>('../../assets/user.png');
  currentPhotoUrl = this.photoUrl.asObservable();
  this.changeMemberPhoto(this.currentUser.photoUrl);

constructor(private http: HttpClient) { }

changeMemberPhoto(photoUrl: string) {
  this.photoUrl.next(photoUrl); 
}

login(model: any) {
  return this.http.post(this.baseUrl + 'login', model).pipe(
    map((response: any) => {
      const user = response;
      if (user) {
        localStorage.setItem('token', user.token);
        localStorage.setItem('user', JSON.stringify(user.user));
        this.decodedToken =  this.jwtHelper.decodeToken(user.token);
        this.currentUser=user.user;
        this.changeMemberPhoto(this.currentUser.photoUrl);
      }
    })
  );
}

register (model: any) {
  return this.http.post(this.baseUrl + 'register', model);
}

loggedIn() {
  const token = localStorage.getItem('token');
  return !this.jwtHelper.isTokenExpired(token);
}

}
从'@angular/core'导入{Injectable};
从'@angular/common/http'导入{HttpClient};
从“rxjs”导入{BehaviorSubject};
从“rxjs/operators”导入{map};
从'@auth0/jwt'导入{JwtHelperService};
从“../../environments/environment”导入{environment};
从“../\u models/User”导入{User};
@注射的({
providedIn:'根'
})
导出类身份验证服务{
baseUrl=environment.apiUrl+'auth/';
jwtHelper=新的JwtHelperService();
解码:任何;
当前用户:用户;
photoUrl=new BehaviorSubject('../../assets/user.png');
currentPhotoUrl=this.photoUrl.asObservable();
this.changemberphoto(this.currentUser.photoUrl);
构造函数(私有http:HttpClient){}
changeMemberPhoto(photoUrl:string){
this.photoUrl.next(photoUrl);
}
登录(型号:任意){
返回this.http.post(this.baseUrl+'login',model).pipe(
map((响应:任意)=>{
const user=响应;
如果(用户){
localStorage.setItem('token',user.token);
setItem('user',JSON.stringify(user.user));
this.decodedToken=this.jwtHelper.decodeToken(user.token);
this.currentUser=user.user;
this.changemberphoto(this.currentUser.photoUrl);
}
})
);
}
寄存器(型号:任意){
返回this.http.post(this.baseUrl+'register',model);
}
loggedIn(){
const token=localStorage.getItem('token');
return!this.jwtHelper.isTokenExpired(令牌);
}
}

我检查了两次或三次,没有发现任何打字错误,有人知道是什么导致了这个问题吗?谢谢

类中不能直接包含
this.changemberphoto(this.currentUser.photoUrl)
。它应该在类方法内部或构造函数内部,最好在定义了
currentUser
之后。非常感谢。这真是一个愚蠢的错误。删除此行后,问题已修复。它已用于登录方法中。