如我所见router: Router和router.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) 我想在创建 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'
当我不想定义它们时,是否必须使用'/'forpath和domain参数?