• AngularJs之二


    今天先讲一个angularJs的表单绑定实例:

    <div ng-app="myApp" ng-controller="formCtrl">
      <form novalidate>
        姓:<input type="text" ng-model="user.xing"><br>
        名:<input type="text" ng-model="user.ming"><br>
        <button ng-click="reset()">RESET</button>
      </form>
      <h2 style="color:#F00">新值 = {{user }}</h2>
      <h2>原值 = {{master}}</h2>
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('formCtrl', function($scope) {
        $scope.master = {xing:"张", ming:"三"};
        $scope.reset = function() {
            $scope.user = angular.copy($scope.master);
        };
        $scope.reset();
    });
    </script>

    注:novalidate 属性是在 HTML5 中新增的。禁用了使用浏览器的默认验证。

    接下来写两个angularJs循环列举数组

    <div ng-app=“” ng-init=“car=[‘宝马’,‘奥迪’,‘奔驰‘,’保时捷’,’法拉利’]">  <p>使用 ng-repeat 来循环数组</p>  <ul>    <li ng-repeat="x in car"> {{ x }}  </li>  </ul></div> 
    <div ng-app=“” ng-init=“names=[{name:‘王小波’,class:‘傻子班’},{name:‘王如花’,class:‘大班’},{name:‘武则天’,class:‘预科班'}]">
              <ul>
       <li ng-repeat="x in names">  {{ x.name + ', ' + x.class }} </li>
                </ul>
    </div>
  • 相关阅读:
    错题集知识(持续更新)
    Java 初始化过程
    java基础自定义测试异常类
    1049 数列的片段和 (20 分)
    1044 火星数字 (20 分)
    1048 数字加密(20分)
    js 全选反选和全不选
    robust programmings
    gdb define command
    好久没有破解别人的无线了, 重温一下
  • 原文地址:https://www.cnblogs.com/liulijun330/p/6224360.html
Copyright © 2020-2023  润新知