2015-11-25 83 views
0

我收到以下錯誤,不知道爲什麼

Error: [$injector:unpr] Unknown provider: $timeOutProvider <- $timeOut <- alert

控制器\ register.js

angular.module('testApp') 
    .controller('RegisterCtrl', function ($scope, $rootScope, $http, alert) { 
    $scope.submit = function() { 

     var url = '/'; 
     var user = {}; 

     $http.post(url, user) 
     .success(function (res) { 
      alert('Success', 'OK!', 'You are now registered'); 
     }) 
     .error(function (err){ 
      alert('warning', 'Oops!', 'could not register'); 
     }); 
    }; 
    }); 

服務\ alert.js

angular.module('testApp') 
    .service('alert', function ($rootScope, $timeOut) { 
    var alertTimeout; 
    return function(type, title, message, timeout){ 
     $rootScope.alert = { 
     hasBeenShown: true, 
     show: true, 
     type: type, 
     message: message, 
     title: title 
     }; 
     $timeOut.cancel(alertTimeout); 
     alertTimeout = $timeout(function() { 
     $rootScope.alert.show = false; 
     }, timeout || 2000); 
    } 
    }); 

app.config.js

angular.module('testApp').config(function ($urlRouterProvider, $stateProvider) { 

    $urlRouterProvider.otherwise('/') 

    $stateProvider 
    .state('main', { 
    url: '/', 
    templateUrl: '/views/main.html' 
    }) 
    .state('register', { 
    url: '/register', 
    templateUrl: '/views/register.html', 
     controller: 'RegisterCtrl' 
    }); 
}) 
+0

該服務被命名爲$超時,而不是$超時。 –

+0

'$ timeout' - 套管非常重要 – JAAulde

回答

1

timeouttimeOut

.service('alert', function ($rootScope, $timeout) { 
相關問題