我刚刚升级到 Ubuntu 20.04。我在虚拟环境中使用 Django 处理 python 3.7 项目,所以即使使用升级的发行版(涉及安装 python 3.8),我也有信心我的 venv 仍然可以工作。不幸的是,事实并非如此:当我激活我的 venv 时,python 的解释器仍然是 3.8 版本,没有任何作用。python 3.7 完全缺失。我该怎么做才能恢复我的项目?
operating-system upgrade linux-distro python-3.x python-venv
我正在使用ngx-cookie-service包来存储一些与我的应用程序相关的数据。我需要将此 cookie 保存在基本路径上'/',因此每次我都确切地知道如何检索它。我的这个 cookie 需要更新,当发生这种情况时,新的 cookie 必须存储在相同的路径中(所以在 中'/')。问题是,有时当我刷新页面时,新的 cookie 会保存在新路径中,因此当我尝试用它检索它时this.cookieService.get(cookieName, '/')显然会失败。尽管我明确声明使用'/'as path ,但还是会发生这种情况。它并不总是发生,这会导致调试更加困难。
这是我使用cookies的服务
const urlParamsCookieName = 'errepiuapp-url-params';
/**
* This service keeps track of the keys used to retrieve objects from the backend.
*/
@Injectable({
providedIn: 'root'
})
export class KeyLookupService {
private _lookupUrlSegments = ['students', 'macro', 'lto', 'sto', 'reports'];
private _paramsMap$: BehaviorSubject<Map<string, any>>;
private get paramsMap() {
return this._paramsMap$.getValue()
}
constructor(
private cookieService: CookieService,
private router: …Run Code Online (Sandbox Code Playgroud) cookies setcookie angular-cookies angular ngx-cookie-service
我有一个组件,它在初始化时从 api 中检索学生信息。这是我的cmponent-version1上的onIniti代码
ngOnInit(): void {
if(!this.student) {
this.studentsService.getStudentDetail(this.id).subscribe(
(response: Student) => {
this.student = response;
},
error => console.log(error)
)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的student-service-version1 中的函数
getStudentDetail(id: number): Observable<Student> {
return this.httpClient.get<Student>(`${this.studentsUrl}${id}/`, this.baseService.httpOptions);
}
Run Code Online (Sandbox Code Playgroud)
一切正常。现在,仅出于教学目的(我是 javascript/typescript 的新手),我想重构我的服务以使用单个get函数,该函数在不带参数的情况下调用时返回学生列表,而是返回学生详细信息使用特定 ID 调用时的信息。这是学生服务版本2
getStudents(id?: number): Observable<Student[]> {
if(id)
return this.httpClient.get<Student[]>(`${this.studentsUrl}${id}/`, this.baseService.httpOptions);
else
return this.httpClient.get<Student[]>(this.studentsUrl, this.baseService.httpOptions);
}
Run Code Online (Sandbox Code Playgroud)
鉴于我的函数的签名声明它返回一个可观察的学生数组,在我的组件中,我需要一种从Student[]到Student的类型转换。我是这样做的: component-version2
ngOnInit(): void {
if(!this.student) {
this.studentsService.getStudents(this.id).subscribe(
(response: Student[]) => {
this.student = response[0] as …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 9。我需要在导航开始后立即知道哪个将是目标网址。我想做这样的事情:
constructor(router: Router) {
this.router = router;
}
this.router.events.pipe(
filter(event => event instanceOf NavigationStart),
map(event => {
//get somehow the destination url of this navigation just started
})
).subscribe()
Run Code Online (Sandbox Code Playgroud)
有没有办法只使用 Angular Router来实现这一点?
angular ×3
angular9 ×1
arrays ×1
cookies ×1
javascript ×1
linux-distro ×1
observable ×1
python-3.x ×1
python-venv ×1
setcookie ×1
typescript ×1
upgrade ×1
url-routing ×1