我想從一個類中的 CookieService 匯出一個值并將其匯入另一個類,然后我想在我的網站上顯示匯入的值。下面是我的代碼。
我嘗試過的 Cookie 服務和匯出:
public login(code: string, state: string) {
const paramsString = `?code=${code}&state=${state}`;
this.oAuthService.getToken(paramsString).subscribe((response) => {
const dateNow = new Date();
dateNow.setSeconds(dateNow.getSeconds() 720);
this.cookieService.set("access_token", response.access_token, {expires: dateNow});
this.cookieService.set("user_info", response.user_info.user_name, {expires: dateNow});
this.cookieService.set("user_email", response.user_info.email, {expires: dateNow});
this.cookieService.set("user_id", response.user_info.user_id, {expires: dateNow});
});
}
public setUserName() {
return this.cookieService.get("user_info");
}
我試圖通過這樣做匯入它,匯入來自類 AppComponent:
readonly random?: AppComponent
然后我嘗試在網站上顯示 exportet 值,但這不起作用:
<div class="row">
<div class="col-sm margin-top-3">
Order Permissions for {{random.setUserName().toString()}}
<br>
<button
style="width: 10%"
id="orderSinglePermission"
class="button button--primary margin-top-3"
> Order
</button>
</div>
uj5u.com熱心網友回復:
我認為不可能以這種方式在插值中使用函式,因此您可以在 TS 檔案中執行此操作并在 HTML 中使用值。
例如:
.ts 檔案:
constructor(your service name){}
get userName(){
return this.serviceName.setUserName();
}
html:
{{userName().toString()}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/358477.html
上一篇:在Github中創建github.io組態檔時.md.html.rmd檔案有什么區別?
下一篇:自己行中影像的CSS選擇器
