And then you can replace <div class="hero-video"> with <div class="hero-video" ng-controller="myController">. This ensures that your view is using your new controller.
When the image/media has been loaded, the URL is available in your view via $scope.image.mediaLink.
I'm using a directive to get the image source on the element attribute, then I use mediaResouce service to get the media and set the src to the element.
Sorry, but I can't figure out the issue with that. Can you post the full code of both the controller and the HTML of the view?
IMO, it's not ideal to use the media resource in the controller especially in case your view needs to display multiple media sources (multimedia picker for example) because you will need to duplicate the "mediaResource.getById" for each media.
By adding a directive to the DOM element, you can modify it the DOM element anyhow you want and you can reuse your directive on other elements too.
Umbraco 8 Backoffice Angular Media items
Hi all,
Quick question how should i translate umb://media in the backoffice to a image url with a Angular component(Block list item).
Thank you in advance
Hi Julien,
You can use the
mediaResource
resource in Angular:https://our.umbraco.com/apidocs/v8/ui/#/api/umbraco.resources.mediaResource
Usage is something like:
So i have this small peace of code. How does that work todo some javascript in it?
I tried this but it results in a error:
GET unsafe:umb://media/a2d4ac2297234fbdac2611bba206d202 net::ERRUNKNOWNURL_SCHEME
Hi again,
I'm not sure how much code you have now, but to hook up your view with some JavaScript, you can create an Angular controller. It could look like this:
The JavaScript file should be registered in Umbraco - you can read more about that here:
https://our.umbraco.com/Documentation/Extending/Property-Editors/package-manifest
And then you can replace
<div class="hero-video">
with<div class="hero-video" ng-controller="myController">
. This ensures that your view is using your new controller.When the image/media has been loaded, the URL is available in your view via
$scope.image.mediaLink
.you dont give a variable to the controller? how it knows what to do?
So far i have a image working but how to send the value to the controller
Hello Julien.
This is a sample code to add the image URL and observe the image changes:
And on your custom HTML:
I'm using a directive to get the image source on the element attribute, then I use mediaResouce service to get the media and set the src to the element.
This works on my side. Hope this helps you too.
Thank you for the answer well i got it working by doing this.
angular.module("umbraco").controller("myController", function ($scope, mediaResource) {
});
this is not perfect for now it is enough. But when i want a second image to get i can not use the getbyId method. Something with Same action twice.
how can i fix that?
Is there any good content for the old angular a course something i can follow? would make much easier i guess
Hello Julien,
Sorry, but I can't figure out the issue with that. Can you post the full code of both the controller and the HTML of the view?
IMO, it's not ideal to use the media resource in the controller especially in case your view needs to display multiple media sources (multimedia picker for example) because you will need to duplicate the "mediaResource.getById" for each media.
By adding a directive to the DOM element, you can modify it the DOM element anyhow you want and you can reuse your directive on other elements too.
AngularJS document can be found at: https://docs.angularjs.org/guide/
Hi @Gii,
Thank you for your help i know it is not the best option. As long as i have only one Block List Components it works fine.
As soon as i add a second component a other component
Header.html
Highlight.html
Then i have two controllers
angular.module("umbraco").controller("myController", function ($scope, mediaResource) {
and i have a second controller.
Results: Multiple actions were found that match the request: GetById on type
Thank you for your help
Hello @Julien,
Sorry for the late response. I was busy so I didn't have the time to check and response.
I'm confused about why did you need to use $scope.$parent.$parent to get the block data.
I've tested with 2 controllers:
I can see that you're using the media object in the response instead of the mediaLink. Maybe that's the issue? This is the HTML markup that I used:
The images appear without any problem.
is working on a reply...