我们如何动态添加/更新元标记,以便 Facebook/Whatsapp 共享对话框选择它们? 我将我的 angular 2 应用程序升级到 angular 4,以便在我们从 API 获取组件中的数据后使用 Meta 服务动态添加/更新元标记。 到目前为止,在我的组件中,我有 我正在使用 up ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在为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.