Example of AngularJS form editing and submission function, angularjs form

Source: Internet
Author: User

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 = "">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.