I recently switched to angular2 universal to make my SPA crawled by a search engine, and Angular Universal is a great option to use this case, I had a problem when I tried to enter dynamic metadata for each page, I tried using ElementRef With Renderer, and I used the angular2-meta service , but it does not work when the platform is not a browser
The following code is my last attempt
import { Component, AfterViewInit, Renderer, Inject, ElementRef } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
import { DomRenderer ,NodeDomRenderer} from 'angular2-platform-node';
import {isBrowser, isNode } from 'angular2-universal';
import { Meta, MetaDefinition } from '../../services/meta.service';
@Component({
selector: 'home',
templateUrl: './home.component.html'
})
export class HomeComponent {
constructor(public meta:Meta) {
const name: MetaDefinition = {name: 'application-name', content: 'Name of my application'};
const desc: MetaDefinition = {name: 'description', content: 'A description of the page'};
const tags: HTMLMetaElement[] = this.meta.addTags([name, desc]);
}
}
When I complete the code in the constructor with the help, if(isBrowser)it is displayed only on the client side, but when I look at the source code of the page, it is not displayed
renderer the this.renderer.createElement,
- , - , angular ASP.NET Core 1.1