2014-03-25 63 views
1

我嘗試添加與requirejs angularjs過濾器在我的看法,但我收到一個錯誤:Angularjs + Requirejs誤差過濾

錯誤:$注射器:unpr未知提供商

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

什麼錯了?

我的文件:

的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'] 
}); 

視圖/ success.html

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

濾波器/ localization.js

'use strict'           

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

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

控制器/ 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;                
    });                      
});                      

回答

0

您的過濾器自舉等你以後應該使用app.register而改叫:

過濾器/ localization.js

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

如果這沒有幫助,建立一個plunker,我會嘗試進一步幫助。

+0

非常感謝,求助!一切皆好! – user2264941

+0

如何選擇答案作爲正確答案?這會在他們遇到你的問題時幫助其他人。 – marcoseu

+0

謝謝,修復它。 – user2264941