Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm new, meaning this is my first hour with AngularJS. I'm trying to get a hang of writing custom filters, and here is my first one:

http://jsfiddle.net/rutwick/UJTdb/

angular.module('myfilters', []).
filter('addon', function(){
        alert('here');
        return function(ip){
            return ip+'-suffix';
        }
    });
angular.module('myapp', ['myfilters']);

If I try using it like so:

<input type="text" ng-model="sometext" />
<h1>{{ sometext | addon }}</h1>

I get a whole lotta errors. So I use it like this:

<input type="text" ng-model="sometext" />
<h1>{{ sometext | filter:addon }}</h1>

No errors, but it doesn't work. The alert doesn't pop. Am I missing something here?

Errors:

Error: Unknown provider: addonFilterProvider <- addonFilter
at Error (<anonymous>)...blah blah file path
share|improve this question
    
what are the errors ? Is there a plunker somewhere? – Ven Jul 26 '13 at 14:26
    
Check now, I've added the error. – Rutwick Gangurde Jul 26 '13 at 14:28
    
You need to register your filter with your app. Is "angular" your application name? – CodeHater Jul 26 '13 at 14:30
    
Works like it should for me: plnkr.co/edit/0PkNAMXdPBp6jVnpns5U?p=preview – Marcel Gwerder Jul 26 '13 at 14:31
    
Here's my entire code: jsfiddle.net/rutwick/UJTdb – Rutwick Gangurde Jul 26 '13 at 14:33
up vote 1 down vote accepted
<body ng-app="myapp">

does the trick! :D

share|improve this answer
    
Thanks man, it worked well! – Rutwick Gangurde Jul 26 '13 at 14:47

See updated variant here http://jsfiddle.net/UJTdb/6/

Basic idea was to set <body ng-app="myapp">

Also I changed a filter function:

filter('addon', function(){
        alert('here');
        return function(ip){
            return ip || '' +'-suffix';
        }
    });
share|improve this answer
    
Thanks a lot, voted up! – Rutwick Gangurde Jul 26 '13 at 14:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.