user3718908x100
user3718908x100

Reputation: 8529

Get src value of image in angular

i have a directive with an isolated scope on my page, now inside this directive i dynamically set the src attribute of the img with ng-src, however i now want to get that src value outside of the isolated scope, in my parent controller, i would like to know how to do it. This is just an example of what i want to do:

<div ng-controller="ParentController">
    <directive action=""></directive>
</div>

This is the directive's html:

<img ng-src="{{ src }}" id="img-preview"/>

I want to be able to get the value of ng-src from inside my ParentController despite the fact that my directive uses an isolated scope, is that possible and if so then how do i do it?

Edit: The directive here is a directive for handling images, so all the uploads etc are done from within the directives controller, now i want to get the value returned from the server in my ParentController from the directive's controller.

Upvotes: 0

Views: 2763

Answers (1)

lostintranslation
lostintranslation

Reputation: 24583

@ngLover is correct. Pass it into your directive from the parent.

<div ng-controller="ParentController">
    <directive action="" action-img-src="imgSrc"></directive>
</div>

Then in your directive:

<img ng-src="{{ actionImgSrc }}" id="img-preview"/>

Upvotes: 2

Related Questions