0

I have a directive which has a link function something like:

 scope: {
                target: '@',
                fooFunction: '&'
            },
link:
   scope.$apply(attrs.fooFunction);
var fooValue= scope.fooFunction(data,scope.target);

in my controller i have defined this function as :

$scope.fooFunction= function (data, target) {
//some code here
}

When I use this in the html, I write like this:

<div some-directive  foo-Function="fooFunction(ctrl.data,'hardCoded')"  target="actualValue"></div>

where I am using myController as ctrl.

My question is that even when I am passing the value as scope.target it always picks the hardCoded value. Is there any way I can pass the value from the scope.target instead of the hard coded value?

1 Answer 1

1

As you have mention target as @ so you need to use {{}} to evaluate that attribute value, which would be treated as one way binding.

Like you could have value inside your controller actualValue variable and then you could bind that like target="{{ctrl.actualValue}}"

Markup

<div some-directive 
  foo-function="fooFunction(ctrl.data,'hardCoded')"
  target="{{ctrl.actualValue}}">
</div>
Sign up to request clarification or add additional context in comments.

7 Comments

Apologies if my question confused you , my question is that : From my directive I am calling : var fooValue= scope.fooFunction(data,scope.target); but the value is passed as 'hardcoded' and not the value from the function.
@Raghav the answer which I gave, is what you wanted?
please see my comment above
Sorry let me explain again. So if you see my directive I have this method call : var fooValue= scope.fooFunction(data,scope.target); which calls the controller method. In the controller function $scope.fooFunction= function (data, target) I get the values as target ='hardcoded' but I am passing scope.target which has the value 'actualValue'
@Raghav inside directive you are using controllerAs?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.