zoukankan      html  css  js  c++  java
  • AngularJS初接触

    todo.json

    [
      {
        "action": "Buy Flowers",
        "done": false
      },
      {
        "action": "Get Shoes",
        "done": false
      },
      {
        "action": "Collect Tickets",
        "done": true
      },
      {
        "action": "Call Joe",
        "done": false
      }
    ]

    todo.html

    <!DOCTYPE html>
    <html ng-app="todoApp">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>TO DO List</title>
        <meta charset="utf-8" />
        <link href="css/bootstrap.css" rel="stylesheet" />
        <link href="css/bootstrap-theme.css" rel="stylesheet" />
        <script src="js/angular.js"></script>
        <script>
            var model = {
                user: "Adam",         
            };
    
            var todoApp = angular.module("todoApp", []);
    
            todoApp.run(function ($http) {
                $http.get('todo.json').success(function (data) {
                    model.items = data;
                });
            });
            todoApp.controller("ToDoCtrl", function ($scope) {
                $scope.todo = model;
    
                $scope.incompleteCount = function () {
                    var count = 0;
                    angular.forEach($scope.todo.items, function (item) {
                        if (!item.done) {
                            count++;
                        }
                    });
                    return count;
                }
    
                $scope.warningLevel = function () {
                    return $scope.incompleteCount() < 3 ? "label-success" : "label-warning";
                };
    
                $scope.addNewItem = function (actionText) {
                    $scope.todo.items.push({ action: actionText, done: false });
                };
            })
        </script>
    </head>
    <body ng-controller="ToDoCtrl">
        <div class="page-header">
            <h2>
            {{todo.user}}'s To Do List
                <span class="label label-default" ng-class="warningLevel()" ng-hide="incompleteCount() == 0">{{incompleteCount()}}</span>
            </h2>
        </div>
        <div class="panel">
            <div class="input-group">
                <input class="form-control"  ng-model="actionText"/>
                <span class="input-group-btn">
                    <button class="btn btn-success" ng-click="addNewItem(actionText)">Add</button>
                </span>
            </div>
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>Description</th>
                        <th>Done</th>
                    </tr>
                </thead>
                <tbody>
                   <tr ng-repeat="item in todo.items|orderBy:'action'">
                       <td>{{item.action}}</td>
                       <td><input type="checkbox" ng-model="item.done" /></td>
                   </tr>
                </tbody>
            </table>
        </div>
    </body>
    </html>
  • 相关阅读:
    [转]windows下安装Object-C开发环境
    [转]Creating Unit Tests for ASP.NET MVC Applications (C#)
    [转]如何在.NET MVC中使用jQuery并返回JSON数据
    [转]发送邮件提示“551 User not local; please try ”错误的原因及解决办法
    getHibernateTemplate().saveOrUpdate 不运行
    1503171912-ny-一道水题
    HDU 3466 Proud Merchants(01背包)
    error while loading shared libraries: libevent-1.x.so.1
    Android开发实例之闹钟提醒
    iOS 处理方法中的可变參数
  • 原文地址:https://www.cnblogs.com/marshhu/p/6750531.html
Copyright © 2011-2022 走看看