Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I trying to add angularjs filter with requirejs in my view, but I receive an error:

Error: $injector:unpr Unknown Provider

http://docs.angularjs.org/error/$injector/unpr?p0=localizationFilterProvider%20%3C-%20localizationFilter

Whats wrong?

My Files:

index.html

<!DOCTYPE html>
<html>
    <head>
        <script data-main="/static/js/application/main" src="/static/js/libs/require.min.js"></script>
    </head>

    <body>
        <div class="page" ng-view></div>
    </body>
</html>

app.js

'use strict';                                                                                            

define(                                                                                                  
    [                                                                                                    
        'angularAMD',                                                                                    
        'angular-route',                                                                                 
        'angular-animate'                                                                                
    ],                                                                                                   
function (angularAMD) {                                                                                  

    var app = angular.module('FilmOrder', ['ngRoute', 'ngAnimate']);                                     

    app.config(['$routeProvider', function($routeProvider) {                                             

        $routeProvider                                                                                   
            .when('/',                                                                                   
                angularAMD.route({                                                                       
                    templateUrl: 'static/js/application/views/success.html',                             
                    controllerUrl: 'application/controllers/Success',                                    
                    controller: 'Success'                                                                
                })                                                                                       
            )                                                                                            

            .otherwise({redirectTo: '/'});                                                               
    }]);                                                                                                 

    angularAMD.bootstrap(app);                                                                           

    return app;                                                                                          
});             

main.js

require.config({

    baseUrl: "static/js",

    paths: {
        'angular':          'libs/angular.min',
        'angular-route':    'libs/angular-route.min',
        'angular-animate':  'libs/angular-animate.min',
        'angularAMD':       'libs/angularAMD.min'
    },

    shim: {
        'angularAMD': ['angular'],
        'angular-route': ['angular'],
        'angular-animate': ['angular']
    },

    deps: ['application/app']
});

views/success.html

<div class="success">
    <div class="success_head">
        {{"Пожалуйста, убедитесь в правильности указанных данных." | localization:'index'}}
    </div>
</div>

filters/localization.js

'use strict'                                           

define(['application/app'], function (app) {           

    app.filter('localization', function () {              
        return 'test';                                       
    });                                                   
});        

controllers/Success.js

define(                                                                                   
    [                                                                                     
        'application/app',                                                                
        'application/filters/localization',                                               
        'application/services/Application'                                                
    ],                                                                                    
    function (app) {                                                                      

    'use strict';                                                                            
    app.register.controller('Success', function ($scope) {                                            

        var Success = {};                                                                       
        $scope.Success = Success;                                                               
    });                                                                                      
});                                                                                       
share|improve this question

1 Answer 1

up vote 0 down vote accepted

Your filter is called after bootstrapping so you should be using app.register instead:

filters/localization.js

define(['application/app'], function (app) {           
    'use strict'
    app.register.filter('localization', function () {              
        return 'test';                                       
    });                                                   
});

If this does not help, setup a plunker and I will try to help further.

share|improve this answer
    
Thanks a lot, for help! All is fine! –  user2264941 Mar 26 at 11:47
    
How about selecting the answer as the correct one? This will help others when they come across your question. –  marcoseu Mar 26 at 11:55
    
Thanks, fix it. –  user2264941 Mar 26 at 14:11

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.