0

I am new with angularjs and I am trying to create a filter that remove spaces from a string.

removeSpaces.js

angular.module('filters.stringUtils', [])
.filter('removeSpaces', [function() {
    return function(string) {
        if (!angular.isString(string)) {
            return string;
        }
        return string.replace(/[\s]/g, '');
    };
}])

home.html

<div ng-controller="ItemController">
<p ng-repeat="item in items">
    <a href="/items/{{ item.item_name | removeSpaces }}">{{ item.item_name }}</a>
</p>

itemcontroller.js

angular.module('myApp').controller('ItemController', [
  '$scope', 'Services', '$http','removeSpaces', function($scope, Services, $http,removeSpaces) {
    $http.defaults.headers.common['Accept'] = 'application/json';
    return $scope.services = Services.query();
  }
]);

I get this error:

Unknown provider: removeSpacesFilterProvider <- removeSpacesFilter
1
  • is the filter.stringUtils module noted in the dependencies of myApp? Commented Jun 17, 2015 at 13:50

1 Answer 1

1

In your app you have to use the module for you app.

So do this and it should work

angular.module('myApp', ['filters.stringUtils'])
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.