ngx-meta: dynamically added meta tags does not recognize facebook
I’m submitting a … (check one with “x”)
[ ] Support request => <!-- Please check the repository for a similar issue or PR before submitting -->
Current behavior
Expected/desired behavior
Minimal reproduction of the problem with instructions
import { MetaService } from '@ngx-meta/core';
import { FirstService } from './first.service';
export class FirstComponent {
firstObj : any = {};
constructor(private _metaService: MetaService,
private _firstService: FirstService) {}
ngOnInit() {
this._firstService.getQuestionOfTheWeek(0).subscribe(
res => firstObj = res,
error => this.errorGetRequest(error),
() => this.successGetRequest()
);
}
successGetRequest(){
this._metaService.setTag('og:description', this.firstObj .Desc);
this._metaService.setTag('og:image', this.firstObj .ImageURL);
}
}
What is the motivation / use case for changing the behavior?
Meta tag are getting added it is visible in the chrome developer tool but facebook does not recognize.
Environment
- Angular version: 4.0.0
- Browser:
- Chrome (desktop) version XX
- Chrome (Android) version XX
- Chrome (iOS) version XX
- Firefox version XX
- Safari (desktop) version XX
- Safari (iOS) version XX
- IE version XX
- Edge version XX
- For Tooling issues:
- Node version: XX <!-- run
node --version--> - Platform:
- Others:
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 1
- Comments: 53
@ishan123456789 @thecoconutstudio Somehow the emails got filtered out and I never observed these comments from both of you.
The below code is of course the most horrible hack, but it worked for me when no other solution on net was working. Till Angular team provides a fix, we decided to go with this.
Here’s my partial code.
And in index.html, create template values as below:
@gianpaj I used server side rendering page but still not working. When I am doing view source on browser developer tool than meta tags are available. facebook Sharing Debugger doesn’t shows OG tags.
@gianpaj can you share your full code for meta update because am getting error in
.subscribe((item: Item) => {can’t find name Item am also using same Repo from https://github.com/angular/universal-starter andngx-metathis.meta.setTag('og:image', 'cAngulsadasdar 4 meta service');this.meta.setTag('og:description', res[i].DocDesc);. any one help me out from thisThis it’s mi PoC, I add validations for get the params, and I add a promise depending on params. I know this code can improve, but it’s a PoC
@gianpaj thanks for your kind replay. can you share your full code. so it’s helpful to build my app. because am also using same as your project. hlp me out my main issue is —(when i update after API call its not reflected in view source(Cntrl + U))
Depressing was a good word for it. Has anyone else found a working solution? If not, I’ll look into the @bharath-holla (I would need to hack it further for it to work for my needs) Thanks!
Reading through all the conversation, the result is not exactly clear. Here is what I think everything above means: to make this work with Facebook it is necessary to:
<head>of the statically served prerendered contentIs that correct?
my component class implements
OnInit(see https://github.com/fulls1z3/ngx-meta/issues/118#issuecomment-344852631). I’ve never used or heard ofCanActivate. Hopefully somebody can guide you in the right directionI don’t think that’s true. I don’t know the underlying reasons why exactly it works, but my SSR server runs properly and renders the correct meta-tags in the HTML. View the source of this page for example: https://givebox.xyz/item/H1-ybixCZ
The
og:image,og:url,og:title(and title) are dynamically generated.I think you need to make sure you are running something like
npm run build:ssrandnpm run serve:ssr.See the
package.jsonhttps://github.com/angular/universal-starter/blob/master/package.json#L24related to https://github.com/fulls1z3/ngx-meta/issues/101
this is because (i believe) the components code are executed on the client side and not at server rendering.
Perhaps this could work? https://github.com/angular/universal#universal-gotchas