- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
设置:我有一个页面(有 Angular ),里面有一个中继器。
<tr ng-repeat="row in results.leads">
<td>{{row.SubmittedByName}}</td>
在中继器中,有一列带有一个按钮,可以打开模式来更改该行的数据。反过来,模式有一个用于保存记录的按钮,用于关闭当前模式,打开一个新模式,让用户输入评论,保存,然后关闭模式。
这一切都很好。太棒了。
不起作用的是......当模式关闭时,ng-repeat应该刷新,因为模式中采取的操作实际上会从数据中删除行。如果我手动刷新页面,该行就会消失 - 但如果不刷新页面,则什么也不会发生。
Angular Controller : '使用严格';
angular.module('leadApproval.controllers', []).
//This is the main page core method - The data is loaded here, and the in-table-row buttons work from here.
controller('LeadApprovalCtrl', function ($scope, $location, $modal, api, notificationService) {
$scope.currentPage = 1;
$scope.pageSize = 13;
$scope.loaded = false;
$scope.totalItems = 0;
$scope.head = {};
$scope.sort = {};
$scope.selectedCls = null;
$scope.changeSorting = null;
$scope.setPage = null;
$scope.results = null;
$scope.loadQueue = (function () {
api.queue.load(function (data) {
if (data.error) {
notificationService.error('<h4>An error occurred..</h4>' + data.error);
} else {
$scope.results = data;
$scope.loaded = true;
}
});
});
$scope.acceptLead = function (leadId) {
var modal = $modal.open({
templateUrl: '/Content/LeadApproval/Approved.html',
controller: 'ApprovedCtrl',
windowClass: '',
resolve: { leadId: function () { return leadId; } }
});
modal.result.then(function (result) {
if (result === 'save') {
$scope.loadQueue();
notificationService.success('Lead successfully approved.');
}
});
}
$scope.searchLead = function (id) {
$location.path('search/' + id);
}
$scope.rejectLead = function (leadId) {
var modal = $modal.open({
templateUrl: '/Content/LeadApproval/NotApproved.html',
controller: 'NotApprovedCtrl',
windowClass: '',
resolve: { leadId: function () { return leadId; } }
});
modal.result.then(function (result) {
if (result === 'save') {
$scope.loadQueue();
notificationService.success('Lead successfully removed from queue.');
}
});
};
$scope.editLead = function (id) {
window.location = "/Customers/Edit/" + id;
}
// Open Lead Detail
var leadHistoryOverviewScope = {
item: {}
};
$scope.showLeadDetail = function (customerId, leadId) {
leadHistoryOverviewScope.item = { customerId: customerId, leadOppId: leadId };
var modal = $modal.open({
templateUrl: '/content/leadApproval/leaddetail.html',
controller: 'LeadHistoryCtrl',
windowClass: 'wide-modal-window',
resolve: { childScope: function () { return leadHistoryOverviewScope; } }
});
};
$scope.loadQueue();
}).
// Lead History controller
controller('LeadHistoryCtrl', function ($scope, $modal, $modalInstance, api, notificationService, childScope) {
$rootScope.loaded = false;
$scope.customerLoaded = false;
var historyStartDate = new moment().subtract(6, 'months').format("YYYY-MM-DD");
var historyEndDate = new moment().format("YYYY-MM-DD");
$scope.orders = [];
$scope.history = [];
$scope.showActionButtons = true;
api.queue.queryOrders(childScope.item.customerId, historyStartDate, historyEndDate, function (result) {
$scope.orders = result || [];
$scope.ordersLoaded = true;
});
api.queue.details.get({ id: childScope.item.customerId, leadOppId: childScope.item.leadOppId }, function (result) {
$scope.history = result;
$scope.customerLoaded = true;
});
$scope.acceptLead = function (leadId) {
$modalInstance.close();
var modal = $modal.open({
templateUrl: '/Content/LeadApproval/Approved.html',
controller: 'ApprovedCtrl',
windowClass: '',
resolve: { leadId: function () { return leadId; } }
});
modal.result.then(function (result) {
if (result === 'save') {
$scope.loadQueue();
notificationService.success('Lead successfully approved.');
}
});
}
$scope.rejectLead = function (leadId) {
$modalInstance.close();
var modal = $modal.open({
templateUrl: '/Content/LeadApproval/NotApproved.html',
controller: 'NotApprovedCtrl',
windowClass: '',
resolve: { leadId: function () { return leadId; } }
});
modal.result.then(function (result) {
if (result === 'save') {
$scope.loadQueue();
notificationService.success('Lead successfully removed from queue.');
}
});
};
$scope.editLead = function (id) {
$modalInstance.close();
window.location = "/Customers/Edit/" + id;
}
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
})
;
我注意到的是 $scope.loadQueue();
(如大约 17 行所示)会抛出一个 undefined object 的错误。由于某种原因,“LeadHistoryCtrl”无法看到“LeadApprovalCtrl”中的范围,因此无法刷新 ng-repeat。我什至尝试过将 loadQueue 函数复制到 LeadHistoryCtrl 中,但没有实际效果 - 代码然后起作用......但主页不刷新。
那么,问题是: 如何在 LoadHistoryCtrl 中调用 loadQueue() 来调用 LeadApprovalCtrl 中的方法,并刷新主页 ng-repeat 表?
最佳答案
如果您需要从多个 Controller 访问该功能,通常您会希望将该功能移至服务中。在 Angular 中,您无法从 Controller 直接与另一个 Controller 通信。您可以使用 $scope.broadcast/$scope.emit 来触发此操作。 What's the correct way to communicate between controllers in AngularJS?
关于javascript - 如何在模式关闭时刷新 ng-repeat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29803332/
在angular 6项目中,我使用angular cli命令ng g lierary @some/libName创建了 Angular 库。在我的库中,我有一个需要@ng-bootstrap/ng-b
我在 plunker 有一个简单的例子.我在一个元素上有一个 ng-show,另一个元素有一个选择。选择应该切换显示/隐藏其他(输入)元素。最初将 select 设置为 Yes 会按预期显示其他输入元
我需要一个由其定义的属性(受监控)过滤的数据列表,我不能这样做: ng-if="project.monitored" 因为我需要计算不受监控的数量。 对于这个例子,我简化了从 getProjects(
我知道 ng-show 和 ng-hide 影响元素上设置的类,而 ng-if 控制元素是否呈现为 DOM 的一部分 是否有选择 ng-if 而不是 ng-show/ng-hide 或反之亦然的示例?
我试图理解 ng-if 和 ng-show/ng-hide 之间的区别,但它们看起来相同对我来说。 选择使用其中之一时我应该记住什么区别吗? 最佳答案 ngIf ngIf 指令根据表达式删除或重新创建
我有一个基本问题,通过查看 Angular 文档或 Google 找不到答案,因此我假设这是不可能的,但我想确定一下。 基本上我想要的是使用一个变量,例如$scope.loggedIn,如下所示: H
据我了解ng-show和ng-hide影响元素上设置的类,并且 ng-if控制元素是否呈现为 DOM 的一部分。 是否有选择 ng-if 的指南超过ng-show/ng-hide或者反之亦然? 最佳答
我的 html 中有几个 div。我正在将内容导出为 PDF,当用户单击导出按钮时会下载 PDF。我希望少数 div 的内容不导出/显示在 PDF 中,但应显示在网页上。我已将 ng-if="!isE
我有一个标记按钮,当用户点击它时,标记讨论,然后标记按钮被替换为文本“成功标记”。目前,我在单击标记按钮后无法禁用 ng-click 时遇到了问题。 ng-click 对于文本“已成功标记”仍然存在,
我在 Angular 1.4.7 中有这段代码: console.log('press') 不会在按下任何键时触发。我也尝试使用 keyup 和 keydown,但它们也不起作用。 我知道一个元素需
正如标题中提到的,我不知道如何使用 ng-bind-html 在部分内部呈现 html。 这里有一个 plunker 来说明。 http://plnkr.co/edit/YFfHsahcum7XA8G
将 ng-bootstrap 安装到我的 Angular-CLI(11.0.4) 时出现错误。 什么时候 ng add @ng-bootstrap/ng-bootstrap 还有我的日志文件 [err
我想从另一个 ng-controller 访问 ng-model,这可能吗?如何实现?在下面的代码中,我使用两个 Controller ,第一个 Controller 具有 mddl1,另一个 Con
在我的应用程序中,当我对文章进行 ng-repeat 时,用户单击“我想隐藏并显示一些元素”。为此,我使用的是 videoPlaying[$index],它对于所有具有 ng-hide 的元素都可以正
预信息 我尝试将管理员和客户分开在不同的阶段或 View 中。 这样,管理员可以在将表发布给客户之前对其进行修改。 问题在表格 -> td 中有按钮来控制暂存、释放(显示)或恢复(隐藏)? 所以基本上
这个问题在这里已经有了答案: What are the nuances of scope prototypal / prototypical inheritance in AngularJS? (3
我有以下奇怪的情况 - Controller 片段 - $scope.filterNum = {0: 'filterVal1', 1: 'filterVal2', 2: 'filterVal3', 3
AngularJS 版本:1.3.8 JSFiddle: http://jsfiddle.net/uYFE9/4/ 我一直在开发一个小的 AngularJS 应用程序,遇到了一些问题。我在页面上有一个
我有一个范围对象,其中包含具有 3 个不同图像的对象。我在 div 内显示图像,该图像重复直到范围对象的长度。我有 3 个不同的 img 标签,它们具有 ng-if 属性,并且仅一次显示 3 个图像之
在 AngularJs 中没有提供 ng-enabled 指令。是否有任何适当的理由不在框架中提供该指令,因为当您可以使用 ng- 时,我们同时拥有 ng-show 和 ng-hide隐藏来实现我们的
我是一名优秀的程序员,十分优秀!