简体   繁体   中英

Angular server side rendering dynamic content not showing in page source

I'm using angular universal for server side rendering for SEO. I created html like below. In this html, "Hello" is static content and "World" is coming from rest service dynamically. I can see "Hello World" in browser. But, when I enter view page source in browser, there is only "Hello" not "World". How can I show dynamic content("World") in page source?

page.html

<div>Hello {{dynamicContent}}</div>

page.ts

import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core';    
@Component({selector: 'app-page', templateUrl: './page.component.html', styleUrls: './page.component.scss'] })

export class PageComponent implements OnInit {
  dynamicContent: string = "";

  constructor(private http: HttpClient) { }

  ngOnInit(): void {
    this.http.get('https://localhost:8080/getContent').subscribe(result => {
      this.dynamicContent = result; //Coming from server "World"
    });
  }

In Page source, you might have the value, "World" written like below:

<div>Hello World</div>

Use Chrome's developer tool to check your page source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM