AngularJS——1初学

最近读文章,发现很多做前端开发的程序员都会学习AngularJS,今天我也尝试学习google提供的这个前端框架。

首先介绍一下“指令”,AngularJS 通过被称为 “指令”的新属性来扩展 HTML,以ng-开头,下面介绍常用的“指令”:

引用自http://www.w3cschool.cc/angularjs/angularjs-reference.html

下面是我做的一个简单的例子

<!doctype html>
<html ng-app>
    <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script>

    </head>
    <body>

        <div ng-controller="controller">
            <form novalidate class="css-form">
                Name: <input type="text" ng-model="user.name" required /><br>
                E-mail: <input type="email" ng-model="user.email" required /><br>
                Age: <input type="number" ng-model="user.age" min="1" max="99" required /><br>
                Gender: <input type="radio" ng-model="user.gender" value="male"/>male
                    <input type="radio" ng-model="user.gender" value="female" />female<br>
                <button ng-click="reset()">reset</button>
                <button ng-click="update(user)">save</button>
            </form>
            <pre>form = {{user | json}}</pre>
            <pre>master = {{master | json}}</pre>
        </div>

        <style type="text/css">
            .css-form input.ng-invalid.ng-dirty {
                background-color: #FA787E;
            }
            .css-form input.ng-valid.ng-dirty {
                background-color: #78FA89;
            }
        </style>
        <script type="text/javascript">
            function controller($scope){
                $scope.master = {};
                $scope.update = function(user){
                    $scope.master = angular.copy(user);
                };
                $scope.reset = function(){
                    $scope.user = angular.copy($scope.master);
                };
                $scope.reset();
            }
        </script>
    </body>
</html>
该例中有ng-controller、ng-model、ng-click指令的用法。

在后面的学习中,我将更多的学习AngularJS的原理和相关特性,同时在项目中尝试运用



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值