I'm working on SeoService for my Angular 6 project https://mypleaks.com. I'm trying to add and update Meta tag as my content URL changes dynamically.
I'm able to console.log('18 ' + title); console.log('19 ' + description); but when I'm appending title and description in addTag and updateTag tag only static value('myPleaks | ') getting appended, and can be seen on inspecting page sources on this link https://mypleaks.com/#/content/16/Manikarnika-Teaser-Launch-Kangana-Ranaut-Celebrates-with-Girls-
Can someone tell me what is problem here. Why meta tags not getting updated with dynamic value of the variable.?
export class SeoService {
constructor(public router: Router, public meta: Meta) { }
/**
* updateOgTitle
*/
public updateOgTitleWithURL() {
this.resolveUrl((title: string, description: string) => {
console.log('18 ' + title);
console.log('19 ' + description);
this.meta.updateTag({name: 'title', content: 'myPleaks | ' + title});
this.meta.updateTag({name: 'description', content: description});
this.meta.addTag({property: 'og:title', content: 'myPleaks | ' + title}, true);
this.meta.addTag({property: 'og:description', content: description}, true);
});
}
/**
* resolveUrl
*/
public resolveUrl(cb) {
const state: RouterState = this.router.routerState;
const snapshot: RouterStateSnapshot = state.snapshot;
const url = snapshot.url;
const title = url.substring(url.lastIndexOf('/') + 1, url.length);
cb(title, title);
} }
I'm also getting below log on server console, Is this related somehow..?
headers: HttpHeaders { normalizedNames: Map {}, lazyUpdate: null, headers: Map {} },
status: 0,
statusText: 'Unknown Error',
url: null,
ok: false,
name: 'HttpErrorResponse',
message: 'Http failure response for (unknown url): 0 Unknown Error',
error:
ProgressEvent {
type: 'error',
target:
XMLHttpRequest {
onloadstart: null,
onprogress: null,
onabort: null,
onerror: null,
onload: null,
ontimeout: null,
onloadend: null,
_listeners: [Object],
onreadystatechange: null,
_anonymous: undefined,
readyState: 4,
response: null,
responseText: '',
responseType: 'text',
responseURL: '',
status: 0,
statusText: '',
timeout: 0,
upload: [Object],
_method: 'GET',
_url: [Object],
_sync: false,
_headers: [Object],
_loweredHeaders: [Object],
_mimeOverride: null,
_request: null,
_response: null,
_responseParts: null,
_responseHeaders: null,
_aborting: null,
_error: null,
_loadedBytes: 0,
_totalBytes: 0,
_lengthComputable: false },
currentTarget:
XMLHttpRequest {
onloadstart: null,
onprogress: null,
onabort: null,
onerror: null,
onload: null,
ontimeout: null,
onloadend: null,
_listeners: [Object],
onreadystatechange: null,
_anonymous: undefined,
readyState: 4,
response: null,
responseText: '',
responseType: 'text',
responseURL: '',
status: 0,
statusText: '',
timeout: 0,
upload: [Object],
_method: 'GET',
_url: [Object],
_sync: false,
_headers: [Object],
_loweredHeaders: [Object],
_mimeOverride: null,
_request: null,
_response: null,
_responseParts: null,
_responseHeaders: null,
_aborting: null,
_error: null,
_loadedBytes: 0,
_totalBytes: 0,
_lengthComputable: false },
lengthComputable: false,
loaded: 0,
total: 0 } }