12

I want to know if it is possible to do the following:

<div ng-repeat='article in articles | filter:search'>
...
    <div>
        {{marked(article.body)}}
    </div>
...
</div>

So I want to execute the "marked" function, passing the article body as a parameter and display the generated output.

2 Answers 2

12

Sure, no problem with that syntax ! :)

All you need is to make sur the marked function is defined in the right scope. For instance, let's assume you are in the ArticleCtrl controller :

app.controller('ArticleCtrl', function($scope) {

    // Declare the method in the controller's scope
    $scope.marked = function(article_body) {

         // do whatever you want here
         // and don't forget to return the expected result
         return "LOVE CAPS! " + article_body.toUpperCase();
    };
 });

You can then use {{ marked(something) }} in you template.

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

3 Comments

Ty very much :) Worked like a charm!
Good news. Have fun ! o/
Just a suggestion, for this type or data transformation is recommended build a filter, it use the same logic and can be reused across the whole app.
2

it's possible, but make sure that function will be $scope function.

Of course call function in ng-repeat isn't good idea, try to re think about your architecure and maybe create some model for it.

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.