繁体   English   中英

Angular Meta Service不添加和更新动态标签值

[英]Angular Meta Service not adding and updating dynamic tag values

我正在为Angular 6项目https://mypleaks.com开发SeoService。 我尝试添加和更新Meta标记,因为我的内容URL动态更改。

我能够console.log('18'+ title); console.log('19'+说明); 但是当我在addTag和updateTag标记中附加标题和描述时,仅附加了静态值('myPleaks |'),并且可以在检查此链接上的页面源时看到https://mypleaks.com/#/content/16 / Manikarnika-Teaser-Launch-Kangana-Ranaut与女孩一起庆祝-

有人可以告诉我这是什么问题。 为什么元标记未使用变量的动态值更新?

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);
}  }

我也在服务器控制台的日志下面,这与某种原因有关吗?

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 } }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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