1
A
回答
3
根据这个问题,可以有两种情况。
一旦用户填写了字段并单击SAVE按钮,SAVE按钮将最终发送PATCH请求以保存//更新值。
当用户更改值时,需要进行请求。
为1
你可以保持一个什么样的通过保持一个HashMap得到改变轨道。对所有用户输入字段使用ng-modal
指令。 我们假设有两个输入字段i。 username
和password
。
<input type="text" ng-modal="username" />
<input type="password" ng-modal="password" />
在你的控制器
$scope.userInfo = {
user: $scope.username,
pass: $scope.password
};
现在,如果有的话得到改变,这将反映在通过双向绑定您的视图和模型。
因此,现在您可以比较旧值和新值,并据此发送所需值。
为2
使用角的watchCollection
。
scope.$watchCollection('[username, password]', function() {
// send a request
});
编辑
一个可以使用第二种方法去抖方法
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
_.debounce = function(func, wait, immediate) {
var timeout, args, context, timestamp, result;
var later = function() {
var last = _.now() - timestamp;
if (last < wait && last >= 0) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) {
result = func.apply(context, args);
if (!timeout) context = args = null;
}
}
};
return function() {
context = this;
args = arguments;
timestamp = _.now();
var callNow = immediate && !timeout;
if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
};
来源:https://github.com/jashkenas/underscore/blob/master/underscore.js
1
没有标准的方式。这是另一种无法看守的方法。您可以将“表单”作为更新的参数传递,并使用“表单”来标识哪些控件已变脏。
http://plnkr.co/edit/8Og1m8eM54eOzKMDJtfJ?p=preview
.controller('ExampleController', ['$scope', function($scope) {
$scope.user = {}
var formFields = ['firstName', 'lastName'];
$scope.update = function(form, user) {
$scope.updatedFields = {};
angular.forEach(formFields, function(field) {
if (form[field].$dirty) {
$scope.updatedFields[field] = $scope.user[field];
//Temporarily set the field back to pristine.
//This is only for demo
form[field].$dirty = false;
}
});
};
}]);
你可以使用输入名称和型号相同的字符串。
<input type="text" ng-model="user.firstName" name="firstName"/>
相关问题
- 1. 猫鼬发送数据的角度
- 2. 角度只发送已更改的模型字段或已更改的复制模型
- 3. 如何发送表单数据体Alamofire
- 4. 如何发送json数据表单jQuery?
- 5. 如何发送数据表单?
- 6. Spring Boot只发送已更改的数据
- 7. 如何在发送联系表格7之前更改数据?
- 8. django rest框架评论表不发送数据(如何使用角度js发送和接收json数据)
- 9. 如何通过角度发送数据到服务器2
- 10. 如何将数据发送到角度为REST API
- 11. 发送表单数据xmlhttprequest
- 12. PHP发送表单数据
- 13. 确保发送()数据已发送
- 14. 更新如果数据已更改,则仅触发更新
- 15. 更改主机,标题已发送
- 16. 具有动态更改子表单的复杂角度表格
- 17. 如何触发单元测试的角度ui-select指令的更改事件?
- 18. 角度提交表单数据
- 19. 角:发送复选框表单数据火力
- 20. 如何修改和更新角js中的数据表行?
- 21. 角度图 - 更改图表的颜色
- 22. 如何更改角度传单地图的语言?
- 23. 使用角度跨过域名发布表单数据
- 24. 无法发送表单的POST数据
- 25. 角度$ http发布不发送服务数据
- 26. $在角HTTP如何从表单数据发布中的NodeJS
- 27. 单击链接时不发送表单而发送POST数据?
- 28. 更改数据时无法更新角度2中的模板
- 29. 如何更改角度Cli束路径?
- 30. 如何通知Java程序数据库的数据已更改
角度没有任何建设,为你问 – harishr
我猜你的形式是非常大,还有一个原因,发送的所有数据是不可选的。在这种情况下,您必须编写自己的逻辑来确定发生了什么变化,并且只发送POST中已更改的数据。 –
您应该有一个最终对象发送,比如'$ scope.final_data',并在您的表单中你应该使用一些指令,比如'ng-change',每当你改变一个模型时,将它添加到'final_data'中。 –