不确定的另一个AngularJS菜鸟需要从别人一点点的见解。
我有一个控制器(staffRenewalsController),其基本定义,当用户点击一个表行来编辑它由$ scope.editRow处理该怎么做。
它应该存在,使用$ uibModal模态对话框,找到工作和现在的两个按钮(Save和Cancel)。
问题:保存()有$ scope可用,而Cancel()有$ scope undefined。我在过去几天尝试了很多东西,我不确定为什么Cancel()的$ scope是undefined。我将Save()重命名为任意值,它仍然有$ scope可用。
有人能看看我的缩写代码的下方,在一些启发我在做什么错吗?
app.controller('staffRenewalsController', ['$scope', '$http', 'uiGridConstants', '$uibModal' ,
function($scope, $http, uiGridConstants, $uibModal) {
$scope.editRow = function(grid, row) {
if(row.entity){
debugger
$scope.selectedRow = row.entity;
$scope.selectedRowBackup = $scope.selectedRow;
var renewalNumber = '';
renewalNumber += row.entity.RenewalNo;
var modalInstance = $uibModal.open({
animation: true,
templateUrl: '@Url.Action("View")' + '?renewalNumber=' + renewalNumber,
controller: myCommuteStaffRenewalSingleModalController,
size: 'lg',
scope: $scope,
resolve: {
items: function() {
debugger
return $scope.items;
} ,
}
});
}
}
var myCommuteStaffRenewalSingleModalController = function($scope, uiGridConstants, $uibModal, $http, $uibModalInstance, items) {
debugger
$scope.selectedRecord = $scope.$parent.selectedRow;
debugger
$scope.save = function() {
debugger;
// $scope is present
};
$scope.cancel = function() {
debugger;
// $scope is undefined...why?
$uibModalInstance.dismiss('cancel');
};
};
它看起来像你的括号没有按正确的顺序关闭。我敢肯定有一个右括号在第6行 –
缺少的是什么'myCommuteStaffRenewalSingleModalController'以及为什么被其内定义你的'myTableController'?另外,'items'解析属性后面用逗号分隔的是什么? – Phil
我很抱歉,我试图删除那些不相关的代码,并且为了公司的原因重命名变量来掩盖他们的真实姓名。我错了,现在我已经纠正了。它运行正常,没有在Chrome中报告的错误。感谢您的反馈意见。 – Retroglider