【发布时间】:2018-10-31 09:35:23
【问题描述】:
我已将我的项目从 typescript 2.1.XX 版本迁移到 2.4.2。下面的文件是生成的 jhipster,当我编译文件时它给了我错误:
错误 TS2345:“() => void”类型的参数不可分配给“IServiceProvider”类型的参数。 类型“() => void”中缺少属性“$get”。
您能帮我找出导致编译错误的原因吗?
namespace module.system {
"use strict";
angular
.module(module.appName)
.provider('AlertService', AlertService);
function AlertService () {
this.toast = false;
/*jshint validthis: true */
this.$get = getService;
this.showAsToast = function(isToast) {
this.toast = isToast;
};
getService.$inject = ['$timeout', '$sce'];
function getService ($timeout, $sce) {
let toast = this.toast,
alertId = 0, // unique id for each alert. Starts from 0.
alerts = [],
timeout = 5000; // default timeout
return {
factory: factory,
isToast: isToast,
add: addAlert,
closeAlert: closeAlert,
closeAlertByIndex: closeAlertByIndex,
clear: clear,
get: get,
success: success,
error: error,
info: info,
warning : warning
};
function isToast() {
return toast;
}
function clear() {
alerts = [];
}
function get() {
return alerts;
}
function success(msg, params, position) {
return this.add({
type: 'success',
msg: msg,
params: params,
timeout: timeout,
toast: toast,
position: position
});
}
function error(msg, params, position) {
return this.add({
type: 'danger',
msg: msg,
params: params,
timeout: timeout,
toast: toast,
position: position
});
}
function warning(msg, params, position) {
return this.add({
type: 'warning',
msg: msg,
params: params,
timeout: timeout,
toast: toast,
position: position
});
}
function info(msg, params, position) {
return this.add({
type: 'info',
msg: msg,
params: params,
timeout: timeout,
toast: toast,
position: position
});
}
function factory(alertOptions) {
let alert = {
type: alertOptions.type,
msg: $sce.trustAsHtml(alertOptions.msg),
id: alertOptions.alertId,
timeout: alertOptions.timeout,
toast: alertOptions.toast,
position: alertOptions.position ? alertOptions.position : 'top right',
scoped: alertOptions.scoped,
close: function (alerts) {
return closeAlert(this.id, alerts);
}
};
if(!alert.scoped) {
alerts.push(alert);
}
return alert;
}
function addAlert(alertOptions, extAlerts) {
alertOptions.alertId = alertId++;
let that = this;
let alert = this.factory(alertOptions);
if (alertOptions.timeout && alertOptions.timeout > 0) {
$timeout(function () {
that.closeAlert(alertOptions.alertId, extAlerts);
}, alertOptions.timeout);
}
return alert;
}
function closeAlert(id, extAlerts) {
let thisAlerts = extAlerts ? extAlerts : alerts;
return closeAlertByIndex(thisAlerts.map(function(e) { return e.id; }).indexOf(id), thisAlerts);
}
function closeAlertByIndex(index, thisAlerts) {
return thisAlerts.splice(index, 1);
}
}
}
}
【问题讨论】:
标签: typescript