【发布时间】:2015-12-08 19:21:20
【问题描述】:
我的代码如下:
var module = ons.bootstrap('my-app', ['onsen','ngSanitize','ngCookies','ngStorage']);
module.factory('methodService', [ '$scope', '$timeout', '$http',
'$localStorage', 'alertService',
function($scope, $timeout, $http, $localStorage, alertService){
}]);
module.factory('alertService', function () {
var data = {
title: 'Alert',
message: ''
}
return {
getTitle: function () {
return data.title;
},
setTitle: function (title) {
data.title = title;
},
getMessage: function () {
return data.message;
},
setMessage: function (message) {
data.message = message;
},
alert : function(){
ons.notification.alert({
message: data.message,
title: data.title
});
}
};
});
还有一个错误Error: [$injector:unpr] Unknown provider: $scopeProvider
有人知道原因和解决方法吗?
【问题讨论】:
-
可以这样写吗?
module.factory('methodService', function($scope, $timeout, $http, $localStorage, alertService) { }); -
也有这个错误
-
可能是因为
alertService,你能把那个代码也贴出来吗? -
工厂没有
$scope... -
如何在工厂使用?