angular - 为什么我的 ngFor 看起来像?我正在使用 TransferState
问题描述
我正在使用 Angular 7.0.7 Angular Universal 项目。一切似乎都很好,除了 SEO 部分。我遵循了很多教程,例如https://blog.worldline.tech/2018/03/08/angular-universal.html
节点服务器应该执行 GET 部分以显示已经包含信息的页面,但是当我使用https://search.google.com/structured-data/testing-tool时,没有显示任何 GET 请求。
import { HttpClient } from "@angular/common/http";
import { Component, OnInit, Inject } from "@angular/core";
import { Title, TransferState, makeStateKey } from "@angular/platform-browser";
export class TestComponent implements OnInit {
test;
constructor(
@Inject(PLATFORM_ID) private _platformId: Object,
private titleService: Title,
private transferState: TransferState,
private http: HttpClient
) {}
ngOnInit() {
this.test = [];
let myTransferStateKey = makeStateKey<any>("myDatas");
if (this.transferState.hasKey(myTransferStateKey)) {
this.test = this.transferState.get(myTransferStateKey, {});
this.transferState.remove(myTransferStateKey);
console.log("Test w/o GET");
console.log(this.test);
console.log("transferstate key");
console.log(myTransferStateKey);
} else {
this.http
.get("https://reqres.in/api/users?page=2")
.subscribe(response => {
this.test = response["data"];
this.transferState.set(myTransferStateKey, this.test);
console.log("Test with GET");
console.log(this.test);
console.log("transferstate key");
console.log(myTransferStateKey);
});
}
}
}
<div class="container">
<div class="row">
<div class="col" *ngFor="let item of test">
{{item.email}}
</div>
</div>
</div>
我希望https://search.google.com/structured-data/testing-tool显示用户列表,但它没有,而是显示一个<!---->
.
我也尝试过卷曲,但结果是一样的。
我做错了什么?谢谢你。
解决方案
推荐阅读
- python - 在使用 rabbitmq 服务器在 django 频道层中添加一个组时?rabbitmq服务器连接不上
- javascript - 加载页面以禁用复选框(使用jquery)后,如何使javascript文件在mvc中工作?
- portforwarding - 为什么端口转发在华为路由器中不起作用
- objective-c - NSURLSession dataTaskWithRequest 返回 nil 数据
- c - 为什么 strlen() 函数给出错误的值
- c# - 尝试为用户“chuacw”查找角色时出错。可能的原因是无效的客户端 cookie 或用户重命名
- php - 生成所有案例NUMBER LETTER NUMBER - php
- c++ - 存储可变参数和回调以供以后使用
- loops - 如何在此 AHK 脚本上设置开关?
- python - Pyplot: Drawing figure in a custom scale (both x and y)