首页 > 语言 > JavaScript > 正文

AngularJS表单编辑提交功能实例

2024-05-06 14:45:57
字体:
来源:转载
供稿:网友

研究了下高大上的AngularJS决定试试它的表单编辑提交功能,据说比JQuery强的不是一星半点。
好奇呀,试试吧。。。。。搞了好久,尼玛。。。靠。。靠。。靠。。尼玛 。。靠。。靠。。。。好吧,谁让我手欠呢。

搜索到了很多关于AngularJS Form的案例
如:

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

模仿着我要搞了个AngularJS Form,但是问题来了。。。。
发现初始化时候ng-model 跟 input 标签里的 value 不默契,冲突。。
后来想再AngularJS controller 里预先赋值 $scope.formData = {‘name':'张三'};
可以通过php程序把值赋到这个AngularJS controller里

代码如下:
<!-- AngularJS controller -->
<script>
    var formApp = angular.module('formApp', []);
    function formController($scope, $http) {
        $scope.formData = {'name':'张三','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>
<!--对应form里的input调整-->

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选