Arne Schreuder Arne Schreuder - 1 year ago 80
AngularJS Question

Angular, output from function on expression

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

<div ng-repeat='article in articles | filter:search'>

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download