前端之angular常用方法

<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
 <meta charset="utf-8">
 <title>angular</title>
</head>
<body>

 <div ng-app="myApp">
  <div ng-controller="myCtrl">
    <select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars">
      <option value="">--请选择--</option>
    </select>
    <select ng-model="selectedSites" ng-options="y for (x,y) in sites">
      <option value="">--请选择--</option>
    </select>
    <pre>
      {{selectedCar|json}}
      {{selectedSites|json}}
    </pre>

    <div class="col-md-12">
      <div class="form-inline">
        <label>
          <input type="checkbox" ng-model="plan.lastYear" ng-click="clickLastYear(plan.lastYear)">
         根据上一年xxx生成公区预算明细</label>
      </div>
      <div class="form-inline">
         <label >
          <input type="checkbox"  ng-model="plan.custom" ng-click="clickContent(plan.custom)">
         自定义</label>
      </div>
    </div>
    <div>
      <input type="radio" name="genderJS3" ng-model="genderJS33" value="1">男
      <input type="radio" name="genderJS3" ng-model="genderJS33" value="2">女
      <pre>
        {{genderJS33}}
      </pre>  
    </div>
    <div>
      {{formatDate}}
    </div>
    <div>
     {{now | date : 'yyyy-MM-dd HH:mm:ss'}}
    </div>
     <div>
      <table id="tb_1" cellspacing="0" cellpadding="2" width="100%" border="1">
        <thead>
            <th ng-repeat="hd in headList">{{hd.code}}</th>
        </thead>
        <tbody> 
             <tr ng-repeat="data in tableData">
                <td ng-repeat="hd in headList">
                    <input type="text" ng-model="data[hd.code].value" />
                </td>
            </tr> 
         </tbody> 
      </table>
    </div>

  </div>
 </div>
 <script>
  var app = angular.module('myApp', []);
  app.controller('myCtrl', function($scope,$filter) {
      //复杂对象
      $scope.cars = {
      car01 : {brand : "Ford", model : "Mustang", color : "red"},
      car02 : {brand : "Fiat", model : "500", color : "white"},
      car03 : {brand : "Volvo", model : "XC90", color : "black"} }
      //简单对象
      $scope.sites = {
          site01 : "Google",
          site02 : "Baidu",
          site03 : "Taobao"
       };

      $scope.plan = {
        lastYear:false,
        custom:true
      };
      $scope.clickLastYear=function(lastYear){
          console.log(lastYear);
      }
      $scope.clickContent=function(custom){
        console.log(custom);
      }
      $scope.genderJS33 = "2";
      var today = new Date();
      $scope.formatDate = $filter('date')(today, 'yyyy-MM-dd HH:mm:ss');
      $scope.now=new Date();

      $scope.headList = [
        {code:"packageCounts"},
        {code:"volume"},
        {code:"volumeUnit"},
      ]
      $scope.tableData = [
        {
            packageCounts:{name:"包装件数",value:'1'},
            volume:{name:"体积(方)",value:'2'},
            volumeUnit:{name:"体积单价",value:'3'}
        }
      ]
  });

 </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值