0

I have a string contained in a member to modify and bind to the title attribute of a label. i want to modify the string member using angular Filter. The modification will be based on a object that should be passed to the filter function.

help with the syntax.

Thanks in advance.

Here is the code i have tried

label class="membername" title={{member.name}}

$scope.dalTitleFilter = function (member) {
                return function (value) {

                };
            };
3
  • And What have you tried? Commented Jan 14, 2014 at 13:00
  • i have added the code..please check Commented Jan 14, 2014 at 13:03
  • 1
    docs.angularjs.org/tutorial/step_09 Commented Jan 14, 2014 at 13:06

1 Answer 1

1

You have to declare the filter on your module:

angular.module('myModule')
    .filter('length', function () {
        return function(value) {
            if (value && value.length) {
                return value.length;
            }
            return 0;
        }
    });

Then you can use it like this:

<input type="text" ng-model="value" />
<p>{{value | length}}</p>

If you want to pass parameters to the filter function (returned from the filter block), you just add arguments to the function:

return function(value, argument1, argument2) {

    // Do something with argument1 and argument2

    if (value && value.length) {
        return value.length;
    }
    return 0;
}

Then use it like this:

<input type="text" ng-model="value" />
<p>{{value | length:argument1:argument2}}</p>
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.