Get item by ID within AngularJS html
# help-with-umbraco
j
Hello, I am developing a custom view for a component i am creating in Umbraco using BlockGrid BlockGrid provides me with mediaItemResolver, for example, in the AngularJS html, which works great. However i now need to get a content item by ID. Is this possible? How would i do it? I am trying to render the component in Umbraco for the content editor using BlockGrid. The component allows the content editor to select X number of items, hence by ID as i have the ID of the item selected in the AngularJS html
j
From within AngularJS you can inject the content resource to get content items by ID. Dependant on what you need from the content using the entityresource may perform better. https://apidocs.umbraco.com/v11/ui/#/api/umbraco.resources.contentResource
j
@Jemayn thanks 😄
can i inject it into the .HTML i do have access to the controller
j
@JigitalCharlie if you look at this example in the documentation: https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/build-custom-view-for-blocks#adding-custom-implementation-to-your-view They register their own controller, inject the mediaResource in the function, use it to get an image by its udi, and then set its url to a variable they can call in the view. You'd need to do basically the same, but with the contentResource for content instead of the mediaResource for media 🙂
j
Ah ok, so just build my own custom view and inject, ok :D. Did not realise i could do that with BlockGrid 😄
15 Views