After studying the high-end AngularJS, I decided to try its form editing and submission function. It is said that it is not a little better than JQuery.
Curious, give it a try. . . . . It took a long time to do it, damn. . . Depend on. . Depend on. . Depend on. . Damn. . Depend on. . Depend on. . . . OK, who made me owe it?
I have searched many cases about AngularJS Form
like:
http://www.angularjs.cn/A08j
https://github.com/tiw/angularjs-tutorial
https://github.com/tiw/angularjs-tutorial/blob/master/ng-form.markdown
https://github.com/tiw/angularjs-tutorial/blob/master/ng-form2.markdown
I was imitating that I was going to create an AngularJS Form, but the problem was. . . .
It is found that the ng-model does not have a tacit understanding with the value in the input tag during initialization, and it conflicts. .
Later I wanted to pre-assign $scope.formData = {'name':'Zhang San'};
You can assign the value to this AngularJS controller through the php program.
The code copy is as follows:
<!-- AngularJS controller -->
<script>
var formApp = angular.module('formApp', []);
function formController($scope, $http) {
$scope.formData = {'name':'Zhang San','remark':'Remark'};
$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) {
} else {
}
});
};
}
</script>
<!--Complied input adjustment in form-->
<input type="text" name="name" ng-model="formData.name" placeholder="Role Name">
Later, I searched again and found that there were other ways, such a thing ng-init=”formData.name='Zhang San'”
The code copy is as follows:
<input type="text" name="name" ng-model="formData.name" ng-init="formData.name='Zhang San'" value="">