小编The*_*Tsg的帖子

期望操作员为相似类型或任何角度

我遇到了无法找到解决方案的问题在此处输入图片说明

如我所见router: Routerrouter.url: string。所以我找不到任何解释,为什么它在html中抱怨router.url === '/successlogin'。任何的想法?

更新:我更改了路由器的类型,router.url: String现在还可以,但是我认为它应该工作相反。为什么会这样呢?直到现在,我还认为类型string是“正确的” 类型,而不是String...

我的代码简化了:

的HTML

<div *ngIf="!global.showUnauthorizedMessage || router.url === '/successlogin'" class="beforeFooter"></div>
 <div *ngIf="!global.showUnauthorizedMessage || router.url ==='/successlogin'" id="footer">
Run Code Online (Sandbox Code Playgroud)

零件

import { Router } from '@angular/router';
constructor( public router: Router) { code here }
Run Code Online (Sandbox Code Playgroud)

html typescript angular

6
推荐指数
2
解决办法
2450
查看次数

如何使用 Angular 的 ngx-cookie-service 在我的 cookie 中设置安全标志?

我想在创建 cookie 时在我的 cookie 中设置安全标志。我想我有解决方案,但我想确定以继续。我使用ngx-cookie-service来设置我的 cookie。

这是我的代码:

const now = new Date();
now.setHours(now.getHours() + 8);
const secureFlag = true;
this.cookieService.set('usertype', 'agent', now, '/', '/', secureFlag);
Run Code Online (Sandbox Code Playgroud)

问题是我不知道是否必须像这样声明第 4 个和第 5 个参数,因为如果我不声明它们会显示错误。

例如我试试这个:

const now = new Date();
now.setHours(now.getHours() + 8);
const secureFlag = true;
this.cookieService.set('usertype', 'agent', now, secureFlag);
Run Code Online (Sandbox Code Playgroud)

它警告我 Argument of type 'true' is not assignable to parameter of type 'string'

当我不想定义它们时,是否必须使用'/'forpathdomain参数?

cookies angular ngx-cookie-service

5
推荐指数
2
解决办法
8390
查看次数

标签 统计

angular ×2

cookies ×1

html ×1

ngx-cookie-service ×1

typescript ×1