-
Notifications
You must be signed in to change notification settings - Fork 482
create universal services #309
Comments
we're waiting for the next next release |
|
I'm adding NgPreboot |
@gdi2290 What is the status here? Does it make sense to have so many different things in one issue? As we discussed, we should create a new module under Universal with all the common services people will need. I am modifying the title for this issue to reflect that. |
I'm not sure if it's the right place to ask for it but is there something like NgLink for setting canonical links? it's badly needed for SEO |
@megalepozy I agree with this. We should have one of the universal services that automatically sets the canonical link in the head. Also, related is i18n href lang tags. |
As posted by @Quixomatic, the workaround for now is:
It will still be good to create these universal services, but this workaround is pretty simple and should cover setting the title. |
Is there currently a way to create a new DOM element? |
@threesquared you would do this through normal Angular components. Are you thinking about trying to use the lower level DOM api? If so, that won't work. What is the specific use case where you can't just use a normal component? |
The use case is the same as the above but to also create any other meta tags which are required like opengraph data so they can be rendered on the server side. At the moment I am rather hackily accessing |
Yeah, so meta tags will be part of the service yet to be created. We will update this thread when it is available through the universal api. |
Awesome @jeffwhelpley , turns out me and @gdi2290 need this right now 💯 , so we might just hop on it... |
Nice, that would be awesome. HtmlComponent is part of this as well. We have a Universal mtg tomorrow so can talk about it then on the hangout. |
Using the @Quixomatic workaround provided by @jeffwhelpley, I'm updating my meta descriptions with the following: public setMetaDescription (desc: string) {
let headChildren = this.document.head.children;
for (let i = 0; i < headChildren.length; i++) {
let element = headChildren[i];
if(element.name === 'meta' && element.attribs.name === 'description'){
element.attribs.content = desc;
}
}
} Unfortunately this only works for the server, not the browser. Surely there is a better solution out there that works in both? |
@johnnysainz usually meta tags only matter on the server side. Can you give me some more details about your use case where you think that it is needed on the client side? |
@jeffwhelpley i'm not very experienced with SEO. My understanding is (was) that meta descriptions need to be updated while navigating--same as title. If this is not the case, then thank you for saving me some time! And thanks for Universal!! |
@johnnysainz typically the meta tags are either used by Google when crawling your site (in which case they make separate server side requests for each URL) or site preview within Twitter/Facebook/LinkedIn/etc. In all of those cases, the only thing that matters is the server side. Just trying to brainstorm a bit here, I think the only reason I can think the meta tags would be useful on the client side is when you have a browser plugin that utilizes them for whatever reason (organizing your bookmarks?). In any case, for the important business reasons, you most likely don't need to care about meta tags on the client side. |
As a pretty hacky solution I mentioned above you can access |
closing as |
@gdi2290 @jeffwhelpley mentioned above that this thread would be updated with details of a meta tag service? |
@threesquared do you mind if I use your implementation for now? Works like a charm :) |
@threesquared please see PR angular/angular#12322 for more details on the Meta Service |
@gdi2290 thanks! |
The suggestion in #309 (comment) did not work for me for setting the title serverside. I'm getting a 'data' is undefined error. Works fine if I use it client-side. |
Not sure if still of interest, but putting together all suggestions found here and around, I've come up with a solution that is working well for me:
If you need this also client side you can simply transform this into a service, and then call it each time the route changes, then use |
@ghego1 i tried to use your for loop to set meta tags in the InterfaceServer
But im gettings this error: "No provider for ElementRef!", can you help me? |
@DBuit, I think the problem is that you are doing this in a Service. I implemented this in a component, and then passed to the service the rendered object. I have not yet studied how Angular2 works behind the scenes so I'm unable to provide you a full description of why this can't be delegated entirely to a Service, but I can share with you the following working code :-) Component:
And then the service:
|
Does this work well with dyanmic link and script tags from an external service? |
hi @ilDon, your solution does not work when we open view page source angular (SSE), can you please give support with angular SSE as well, |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
blocked via angular/angular#7455
NodeDomSharedStylesHost
added via e8befd4renamed via d804d7a
The text was updated successfully, but these errors were encountered: