0

I have written an angular function that works fine. Now, I want to write another angular function that calls the first function. How can I do this?

app.controller("AppCtrl",function($scope,$location,$http,$compile,$rootScope){
    $scope.func1 = function(param1,param2){
        ... // function body
    };
    $scope.func2 = function(param3) {
        var value = "someValue";
        $scope.func1(value,param3);
    };
});

Unfortunately func2() doesn't work, even though fucn1() works if I call it directly (e.g., <div ng-click="func1(val1,val2)">Click Here</div>. Why?

UPDATE:

It's because I'm doing the following:

<ul>
    <li ng-click="func2('{{item.value}}') ng-repeat="item in items">Item</li>
</ul>

For some reason {{item.value}} is not being compiled in the ng-repeat. I can inspect the HTML and see that the values are there, but the ng-click doesn't do anything. However, if I manually enter a value for the parameter in func2, then it works. So, now my questions is: How do I compile items in an ng-repeat?

7
  • 1
    There should be no problem with this. What behaviour or error are you receiving. Commented Nov 30, 2013 at 23:14
  • 2
    Explain "doesn't work". Commented Nov 30, 2013 at 23:26
  • "value" is undefined at func2 Commented Nov 30, 2013 at 23:36
  • 2
    Where are you expecting value to come from? Commented Nov 30, 2013 at 23:41
  • @DavinTryon I have updated the question. For some reason the items in my ng-repeat are not being compiled. Commented Dec 1, 2013 at 3:32

1 Answer 1

1

I fixed your example here: http://jsfiddle.net/CsffM/

The problem is that you are using brackets in your expression, Insted, do this:

<li ng-click="func2(item.value)" ng-repeat="item in items">Item</li>

I hope I have helped!

Sign up to request clarification or add additional context in comments.

Comments

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.