表单使用

1.form.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello AngularJS</title>
    <meta name="keywords" content="HelloWorld" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" name="viewport">
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">

    <script src="js/common/angular.min.js"></script>
    <script src="js/common/angular-ui-router.min.js"></script>

</head>
<body ng-app="notesApp" ng-controller="MainCtrl as ctrl">
<form ng-submit="ctrl.submit()">
    <input type="text" ng-model="ctrl.user.username">
    <input type="password"  ng-model="ctrl.user.password">
    <input type="submit" value="submit">
</form>
</body>
<script type="text/javascript">
    angular.module('notesApp',[])
        .controller('MainCtrl', [function(){
           var self = this;
           self.submit = function() {
                console.log('submit with ', self.user);
           }
        }]);
</script>
</html>

2.页面展示

数据对象自动封装

3. 解析

  • 使用ng-submit比ng-click好处是,回车他也可以提交。
  • 前端ctrl.user.username和ctrl.user.password在输入的时候自动生成一个user对象进行封装。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、 form表单标签语法 看下生活案例用图: 生活当中表单使用案例 form表单属性说明 见下面链接:http:...
    joy_蓝蜘蛛阅读 1,374评论 0 9
  • Html中的form表单常用于用户信息的填写和提交,在前端开发中使用较为广泛。 form对象 建立一个form表单...
    CYC_dc68阅读 337评论 0 0
  • 为什么要用表单? 在我们浏览网页的时候,尤其是各种论坛,一般都会要求我们登陆账号,在我们输入完账号密码后,这些数据...
    squall1744阅读 254评论 0 1
  • 痛哭之后 想说一下 昨天看到一句话很震动 “周围没有爱 心里也没有爱 抑郁症和上瘾” 这是我现有生活的写照。 这种...
    LUPOU阅读 234评论 2 1
  • 有很多事情。第一,不能理解她的阴阳怪气,即使身为母亲,也应该尊重并且平等的对待女儿,一个成年的个体。第二,今天...
    九霄ya阅读 123评论 0 0