一、AngularJS的模板绑定机制好像和其$http服务也有必定关系,若是用jQuery Ajax的返回值赋给$scope的做用域变量,整个绑定显示的节奏慢一个事件,神器果真麻烦啊。
二、对hidden input作绑定好像无效
三、AngularJS中对input的ng-model绑定和对Input的value赋值之间存在矛盾。若是绑定了model就没法对value作赋值。
四、input不作ng-model绑定,那验证输入的机制就会有问题:错误提示显示不出来。
五、根据4和5两个条件,对表单数据作初始化最好用ng-model,对$scope的变量作初始化时,只能对一级子属性复制好比$scope.attr1,若是直接对二级属性,$scope.attr1.attr2赋值,由于第一次初始化时可能$scope.attr1这个对象实际尚未建立,会致使代码出错。app
angular 的 ng-model 确实和 input 的 value存在矛盾,可是能够预先把值传递到$scope.formData里
function formController($scope, $http) {
// create a blank object to hold our form information
// $scope will allow this to pass between controller and view
$scope.formData = { 'name':'这里是input预先赋值内容' };
// process the form
$scope.myForm = function() {
$http({
method : 'POST',
url : '/role/edit',
data : $.param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
console.log(data);
if (!data.success) {
// if not successful, bind errors to error variables
//$scope.errorName = data.errors.name;
//$scope.errorSuperhero = data.errors.superheroAlias;
} else {
// if successful, bind success message to message
//$scope.message = data.message;
}
});
};
}
而后再input中写
<input type="text" name="name" ng-model="formData.name" class="form-control" placeholder="Role Name" value="">
这样ng-model="formData.name"就默认赋值了this