AngularJs表在创建/删除/更新后没有更新
AngularJs Table not updated after Create/Delete/update
如果我在数组中创建/更新/删除值,ng表不会更新数据。我需要做一个窗口。位置。reload(),但这不是很"漂亮"。难道在Angularjs中不应该通过2Way数据绑定和自动的$apply循环来完成吗?
也许我忘记了一些东西:
'use strict';
(function() {
class TranslationsComponent {
constructor($http, $scope, $uibModal) {
this.$http = $http;
this.$scope = $scope;
this.$uibModal = $uibModal;
this.langV = [];
}
$onInit() {// getting my Datas
this.$http.get('/api/dict_keys/all/' + 1 + '/' + 1)
.then(response => {
this.langV = response.data;
});
}
// For Example Deleting something with a Modal
// Delete Modal
deleteKey(selectedKey) {
this.$uibModal.open({
scope: this.$scope,
templateUrl: 'delete.html',
controller: ['$scope', '$uibModalInstance', '$http', 'selectedKey',
function($scope, $uibModalInstance, $http) {
$scope.selectedKey = selectedKey;
this.$http = $http;
$scope.close = function() {
$uibModalInstance.dismiss();
};
$scope.delete = () => {
this.$http.delete('/api/dict_keys/' + selectedKey._id)
.then(() => {
//window.location.reload();
//what can i instead of realod do?
toastr.success('The Key is successfully Deleted');
$uibModalInstance.close();
});
};
}
],
resolve: {
selectedKey: () => selectedKey
}
});
}
/* ----------------------------------------- */
angular.module('euconDictionaryApp')
.component('translations', {
templateUrl: 'app/translations/translations.html',
controller: TranslationsComponent
});
})();
在我的。html中,它是一个简单的ng-repeat,显示所有内容,简而言之:
<tr dir-paginate="v in $ctrl.langV |itemsPerPage: 10">
<td>
{{v.Name}}
</td>
<td>
<!-- Delete Key Button -->
<button type="button" class="btn btn-default" ng-click="$ctrl.deleteKey(v)">
</button>
</td>
看起来你需要更新'this。在删除或更新后查看langV'数组的更新。你可以使用javascript的splice方法从数组中删除一个项目。
删除后可以使用
this.langV.splice(this.langV.indexOf(v), 1)
更新后,您可以像
一样更新项this.langV[index] = updateItem
相关文章:
- Mongoose-在更新中删除数组元素
- 谷歌地图/Angular JS:地图更新并不总是反映数据,并且可以't删除标记
- Es6:能够在设置/更新/删除对象属性时调用自定义方法
- 手持:删除行后更新渲染器
- 拖动&删除Fullcalendar.io资源-更新视图
- 如何在使用Javascript删除某一行时更新表
- orderBy$filter在项目删除(拼接)后阻止ng重复列表更新
- 如何使用Extendscript scriptui插入、更新、删除XML元素的值
- 更新分组条形图(转换或删除元素组)
- Chrome扩展程序 - 页面更新两次,然后在YouTube上删除
- 对可观察数组foreach的更新删除了格式化knockoutjs
- ReactJS-这个状态中的数组在删除时被正确更新,但结果是't,直到以后的状态发生变化
- 从数组中删除值,用新的数组总数更新html或'$'如果没有总计
- php使用ajax生成html表,以应用用户操作,如删除、更新和编辑
- 正在更新/删除猫鼬对象属性
- 创建新对象失败,错误代码:没有找到用于更新/删除的对象
- 在数据库表更改/更新/删除时触发jQuery事件
- 在asp.net MVC 4 razor视图中更新删除后的记录号
- 如何处理Angular控制器中的错误从MongoDB数据库更新/删除在Express
- 如何在MongoDB嵌套数组中更新/删除多个索引