关于node、angular的一个练手项目

这是完成的效果 ,可以创建内容 并且传到后台 在localhost:3000端口在这里插入图片描述
这是index.html的内容

 <!--write by sevencute 2018-11-8-->
 <!DOCTYPE html>
<html lang="en" ng-app="App">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>practice angular node</title>
    <link rel="stylesheet" href="./bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/style.css">
</head>
<body>
    <!--top-->
    <div class="jumbotron" style="text-align:center">
        <h1>Note book</h1>
        <p>angular &&node &&bootstrap</p>
    </div>
    <!--body-->
    <div ng-controller="EditorController">
        <div class="row">
            <!--left-->
            <div class="col-sm-4">
                <div class="panel panel-default">
                    <!--heading-->
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <button class="btn btn-primary btn-xs pull-right" ng-click="create()">New note</button>Note
                        </h3>
                    </div>
                   <!--panel body-->
                   <div class="panel-body">
                        <p ng-if="!note.length">no notes</p>
                        <ul class="list-group">
                            <li class="list-group-item"ng-repeat="note in notes" ng-click="view($index)" ng-class="{actice:note.id==contend.id}">{{note.title}}<br>
                            <small>{{note.date|date:'short'}}</small>
                            </li>
                        </ul>
                   </div>
                </div>
            </div>
            <!--right-->
               <div class="col-sm-8">
                   <!--编辑区-->
                   <div class="panel panel-default" ng-hide="editing">
                       <div class="panel-heading">
                           <h3 class="panel-title">{{content.title}}
                               <button class="btn btn-primary btn-xs pull-right" ng-click="editing=true">Edit</button>
                           </h3>
                       </div>
                       <div class="panel-body" markdown="{{content.content}}"></div>
                       <div class="panel-footer">{{content.date|date:'short'}}</div>
                   </div>
                   <!--show-->
                   <form name="editor" class="panel panel-default" ng-show="editing">
                       <div class="panel-heading">
                           <h3 class="panel-title">
                               <input type="text" class="form-control" ng-model="content.title" placeholder="WRITE YOUR NEW NOTE" required>
                           </h3>
                       </div>
                       <!--body-->
                       <div class="panel-body">
                           <div class="row">
                               <div class="col-sm-6">
                               <h3>editor</h3>
                               <textarea class="form-control editor"   rows="10" ng-model="content.content" placeholder="Note Content" required></textarea>
                               </div>
                               <div class="col-sm-6">
                                   <h3>preview</h3>
                                   <div class="preview" markdown="{{content.content}}"></div>
                               </div>
                           </div>
                       </div>
                       <!--foot-->
                       <div class="panel-footer">
                           <button class="btn btn-primary" ng-click="save()" ng-disabled="editor.$invalid">Save</button>
                           <button class="btn btn-danger pull-right" ng-click="remove()"ng-if="content.id">Delete</button> 
                       </div>
                   </form>
               </div>
        </div>
    </div>
   <script src="./bower_components/angular/angular.min.js"></script>
   <script src="./bower_components/showdown/compressed/showdown.js"></script>
   <script src="./js/app.js"></script>
   <script src="./js/editor.js"></script>
</body>
</html>

这是edit.js的内容

angular.module('App').controller('EditorController', function ($scope, $http) {
    $scope.editing = true;//初始化编辑界面隐藏
    $scope.view = function (index) {
        $scope.content = $scope.notes[index];//Notes是后台拉的notes.JSON
    };

    $scope.create = function () {
        $scope.editing = true;
        $scope.content = {
            title: '',
            content: ''
        };
    };
    //save
    $scope.save = function () {
        $scope.content.date = new Date();
        if ($scope.content.id) {
            $http.put('/notes/' + $scope.content.id, $scope.content).success(function (data) {
                $scope.editing = false;
            }).error(function (err) {
                $scope.error = 'cannot update note';
            });
        } else {
            $scope.content.id = Date.now();//是否定义id
            $scope.post('/notes', $scope.content).success(function (data) {
                $scope.notes.push($scope.content);
                $scope.editing = false;
            }).error(function (err) {
                $scope.error = 'cannot updata note';
            });
        }
    };
    //remove
    $scope.remove = function () {
        $http.delete('/notes/' + $scope.content.id).success(function (data) {
            var found = -1;
            angular.forEach($scope.notes, function (note, index) {
                if (note.id === $scope.content.id) {
                    found = index;
                }
            });
            if (found >= 0) {
                $scope.notes.splice(found, 1);
            }
            $scope.content = {
                title: '',
                content: ''
            };
        }).error(function (err) {
            $scope.error = 'connot delete note'
        });
    };

    $http.get('/notes')
    .success(function (data) {
        $scope.notes = data;
    })
    .error(function (err) {
        $scope.error = '无法加载';
    });

});

还有server.js等部分 这是我的码云 代码已经上传
https://gitee.com/cuteSeven/myPracticeForNodeAngular.git

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值