0

how can I call a controller function from html attribute. For example:

Controller function:

$scope.foo = function(id)
{
    return id+1;
}

And here is the html:

<div ng-repeat obj in arr id="foo(obj.id)"></div>

This way I am getting ...id=foo(obj.id) instead of ...id="2" (if obj.id is equal 1).

Thanks!

4
  • 1
    try id="{{foo(obj.id)}}" Commented Jun 15, 2014 at 7:14
  • 1
    you would normally attach it to an event or dump it into the DOM with {{}}... what's the purpose of your code? Commented Jun 15, 2014 at 7:16
  • I have some date I am getting from my server, I wish to change it format this way (changeFormat(obj.date)) Commented Jun 15, 2014 at 7:18
  • if you need to format date to display, the correct way to do it is using angular filter: stackoverflow.com/questions/22432292/… Commented Jun 15, 2014 at 7:19

1 Answer 1

1

to call angular rendering you need to had {{ }}. Try this: id="{{foo(obj.id)}}"

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.