我收到以下错误,不确定原因
错误:[$ injector:unpr]未知提供商:$ timeOutProvider< - $ timeOut < - alert
控制器\ register.js
let versionNumber = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
let buildNumber = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleVersion") as! String
服务\ alert.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');
});
};
});
app.config.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);
}
});
答案 0 :(得分:2)
timeout
而非timeOut
.service('alert', function ($rootScope, $timeout) {