我正在尝试在添加新记录后刷新/重新加载我的页面,但它在我的情况下不起作用。 这是我的控制器,它从新记录表格中的保存按钮后调用。
leads.save = function (isFormValid) {
leads.submitted = true;
if (isFormValid && !leads.exist) {
leadsService.addEditLeads(leads, function () {
leads.submitted = false;
$modalInstance.dismiss('cancel');
$route.reload();
});
//$window.location.reload();
}
};
这是我的服务
_addEditLeads = function (leads, callback) {
var Leads = {
id: leads.id,
title: leads.title,
is_converted: leads.is_converted,
street_address: leads.street_address,
email: leads.email,
lead_name: leads.lead_name,
first_name: leads.first_name,
middle_name: leads.middle_name,
last_name: leads.last_name,
phone_num: leads.phone_num,
postal_code: leads.postal_code,
city: leads.city,
state: leads.state,
country: leads.country,
lead_owner_id: global.User.id,
lead_source_id: leads.lead_source_id,
lead_status_id: leads.lead_status_id,
employees: leads.employees,
industry_id: leads.industry_id,
lead_date: new Date(),
account_id:leads.account_id,
};
var Accounts = {
account_name: leads.account_name,
address: leads.address,
phone: leads.phone,
website: leads.website,
description: leads.description,
employees: leads.employees,
city: leads.city,
state: leads.state,
country: leads.country,
account_owner_id: global.User.id,
industry_id: leads.industry_id
};
resource.user.addEditLead({ Lead: Leads, Accounts: Accounts })
.$promise.then(function (response) {
if (response.success) {
if (Leads.id != 0) {
//Update record
for (var i = 0; i < _leadsObject.data.length; i++) {
if (_leadsObject.data[i].id == Leads.id) {
_leadsObject.data[i] = Leads;
break;
}
}
notifyService.notifySuccess(Leads.title + " updated successfully");
}
else {
//Add new
notifyService.notifySuccess(Leads.title + " added successfully");
Leads.id = response.data;
if (_leadsObject.data != null)
_leadsObject.data.unshift(Leads);
else {
_leadsObject.data = [];
_leadsObject.data.push(Leads);
}
//callback(response.data);
}
if (typeof (callback) == 'function') {
callback();
}
}
}, _errorCallback);
};
控制器通过MVC在数据库中添加数据,我正在使用sql server 2012数据库。
请帮助我?