angular-备忘录

前端之家收集整理的这篇文章主要介绍了angular-备忘录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

今天学习angular,参考教程写了一个小备忘录
功能:新增,删除
html页面

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <Meta charset="UTF-8">
  5. <title>Title</title>
  6. <script src="angular.js"></script>
  7. <style> *{ Box-sizing: border-Box; } .wrap{ width:500px; border:1px solid #ddd; font:16px "Microsoft JhengHei"; } .wrap header{ width:100%; height:40px; background: #e0e0e0; border-bottom:1px solid #eee; text-align:left; text-indent:10px; line-height:40px; } .wrap .body{ display: flex; padding: 10px; } .body_check{ padding:10px; } .memo_input{ flex:1; margin-right:10px; border:1px solid #ddd; height:30px; } .btn{ height:30px; background: #00aaaa; border:1px solid #eeeeee; color: #fff; } .btn_red{ background: #ff2a4e; } </style>
  8. </head>
  9. <body>
  10. <div class="wrap" ng-app="memoApp" ng-controller="memoCtrl">
  11. <header>备忘录</header>
  12. <div class="body">
  13. <input ng-model="memoInput" class="memo_input" type="text" size="50">
  14. <input ng-click="addMemo()" class="btn" type="button" value="新增">
  15. </div>
  16. <div class="body_check">
  17. <div ng-repeat="x in memoList">
  18. <input type="checkBox" ng-model="x.done">
  19. <span ng-bind="x.memoText"></span>
  20. </div>
  21. </div>
  22. <div class="body">
  23. <input ng-click="delMemo()" class="btn btn_red" type="button" value="删除">
  24. </div>
  25. </div>
  26.  
  27. <script src="./js/app.js"></script>
  28. <script src="./js/controller.js"></script>
  29. </body>
  30. </html>@H_740_502@
  31. app

  32. var memoApp = angular.module('memoApp',[]);@H_740_502@ 
  33.  

    controller

  34.  
    memoApp.controller('memoCtrl',function ($scope) {
  35.     $scope.memoList = [];
  36.     $scope.addMemo = function(){
  37.         if($scope.memoInput == "")
  38.         {
  39.             return;
  40.         }
  41.         $scope.memoList.push({memoText:$scope.memoInput,done:false});
  42.         $scope.memoInput = "";
  43.     };
  44.     $scope.delMemo = function(){
  45.         var oldList = $scope.memoList;
  46.         $scope.memoList = [];
  47.         angular.forEach(oldList,function(x){
  48.             if(!x.done)
  49.                 $scope.memoList.push(x);
  50.         })
  51.     }
  52. });@H_740_502@ 
  53.  

    效果图:

猜你在找的Angularjs相关文章