AngularJS表单编辑提交功能实例
作者:bea
研究了下高大上的AngularJS决定试试它的表单编辑提交功能,据说比JQuery强的不是一星半点。 好奇呀,试试吧。。。。。搞了好久,尼玛。。。靠。。靠。。靠。。尼玛 。。靠。。靠。。。。好吧,谁让我手欠呢。 搜索到了很多关于AngularJS Form的案例 如: http://www.angularjs.cn/A08j https://github.com/tiw/angularjs-tutorial https://github.com/tiw/angularjs-t
研究了下高大上的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调整-->
<input type="text" name="name" ng-model="formData.name" class="form-control" placeholder="Role Name">
后来又搜啊搜 发现还有其他办法,这么个东东 ng-init=”formData.name='张三'”
代码如下:
<input type="text" name="name" ng-model="formData.name" ng-init="formData.name='张三'" value="">
有用 | 无用
搜索到了很多关于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调整-->
<input type="text" name="name" ng-model="formData.name" class="form-control" placeholder="Role Name">
后来又搜啊搜 发现还有其他办法,这么个东东 ng-init=”formData.name='张三'”
代码如下:
<input type="text" name="name" ng-model="formData.name" ng-init="formData.name='张三'" value="">
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JavaScript简介
- JavaScript的原型继承详解
- javascript 闭包详解
- PhotoShop给图片自动添加边框及EXIF信息的JS脚本
- 浅析javascript中函数声明和函数表达式的区别
- 不同编码的页面表单数据乱码问题解决方法
- 浅谈javascript中this在事件中的应用
- javascript使用正则表达式实现去掉空格之后的字符
- 分享一个自己写的简单的javascript分页组件
- Linux下编译安装php libevent扩展实例
- jQuery中extend函数详解
- NodeJS使用jQuery选择器操作DOM
- JavaScript将Web页面内容导出到Word及Excel的方法
- javascript上下方向键控制表格行选中并高亮显示的方法
- JS+CSS实现可拖拽的漂亮圆角特效弹出层完整实例
- jQuery实现DIV层淡入淡出拖动特效的方法
- JS实现固定在右下角可展开收缩DIV层的方法
- JS仿iGoogle自定义首页模块拖拽特效的方法
- JS弹出可拖拽可关闭的div层完整实例