2
私はトークンがクッキーである場合、それが正常に動作しますが、私は送信する必要がある場合const accessToken = this.getAccessToken();
Returnステートメント、角度
このメソッドを呼び出すときに、私はここでは2つの方法、
private getAccessToken() {
let token = this.cookie.get(this.accessTokenName);
if (typeof token == "undefined") {
this.rest.get('m2/token')
.then((response) => {
if (response.token) {
this.cookie.put(this.accessTokenName, response.token);
token = response.token;
return token;
};
});
} else {
return token;
}
}
private fetchStores() {
const accessToken = this.getAccessToken();
if (!accessToken) {
this.core.notify('Error - Fail to connect with GWA,Try again!',0);
} else {
this.rest.get(`m2/store/?${this.accessTokenName}=${this.getAccessToken()}`).then((stores) => console.log('stores', (stores)))
}
}
を持っていますトークンを取得するためにAjax呼び出し、私はあなたがあなたの機能にコールバックを実装する必要があると思う私のaccessTokenは未定義のショーで、その後、突然、それは誤り
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
可能な重複https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an -asynchronous-call) –
エラーの完全なトレースをお願いしますか? – trichetriche