Example of AngularJS form editing and submission function, angularjs form
After studying the AngularJS on the tall end, I decided to try its form editing and submission function. It is said that it is better than JQuery.
Curious. Try it ..... After a long time, Nima... .. .. .. Nima .. .. By .... Well, who made me owe it.
I found many cases about AngularJS Form.
For example:
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
Imitating that I want to build an AngularJS Form, but the problem is ....
It is found that during initialization, the ng-model and the value in the input tag do not have a tacit understanding or conflict ..
Later, I want to assign $ scope. formData = {'name': 'zhangsan'} To AngularJS controller '};
You can use the php program to assign the value to this AngularJS controller.
Copy codeThe Code is as follows:
<! -- AngularJS controller -->
<Script>
Var formApp = angular. module ('formapp', []);
Function formController ($ scope, $ http ){
$ Scope. formData = {'name': 'zhang san', 'remark': 'note '};
$ 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>
<! -- Corresponding to input adjustment in form -->
<Input type = "text" name = "name" ng-model = "formData. name" class = "form-control" placeholder = "Role Name">
Later, I searched again and found there are other methods, such a Dongdong ng-init = "formData. name = 'zhang san '"
Copy codeThe Code is as follows:
<Input type = "text" name = "name" ng-model = "formData. name" ng-init = "formData. name = 'zhang san'" value = "">