Frenz
Frenz

Reputation: 747

Angular: Unknown provider

I've created a custom filter. However when I call this filter in my html, I get the error Unknown provider: fixUrlFilterProvider <- fixUrlFilter

Filter Code:

angular.module('TestDemo')
    .filter('fixUrl', 
        function () {
            'use strict';
            return function (relativePath) {
                return 'http://test/' + relativePath;
            };
        }
    );

HTML

<a data-ng-href="{{'Login.aspx' | fixUrl}}" login </a>

Kindly let me know how I can fix this. Thanks in advance.

Upvotes: 0

Views: 265

Answers (3)

Judy007
Judy007

Reputation: 5870

I received this error when I accidentally defined the filter in my controller function instead of after declaring my module. Please make sure that after you have created your todoApp, that directly after, you create custom filter

        //todoApp is an AngularJS module object
    var todoApp = angular.module("todoApp", []);

    //Adding custom filter to demonstrate results
    todoApp.filter("checkedItems", function () {
        return function (items, showComplete) {
            var resultArr = [];
            angular.forEach(items, function (item) {
                if (item.done == false || showComplete == true) {
                    resultArr.push(item);
                }
            });
            return resultArr;
        }
    });

Upvotes: 0

mxp
mxp

Reputation: 180

Usually happens to me when I have forgotten to include the js file.

  • Check that file containing 'TestDemo' is included in the HTML
  • Check the module name matches ng-app
  • If filter and ng-app are different module, check if the filter module is listed as dependency in the ng-app module
  • Sacrifice a goat to the JS gods :)

If the above steps don't help post the index.html, and JS files

Upvotes: 1

Sherman Szeto
Sherman Szeto

Reputation: 2405

Make sure your app is really called "TestDemo", that your html in enclosed inside the "TestDemo" app and that you have this file included in your script tags

Upvotes: 0

Related Questions