0

新手,JS framework但有 Java、JQuery 等背景。(这似乎对 Angular 没有帮助。)

我正在使用 PKozlowski 出色的 Angular适配器,但不知道如何在保存一行时更新 UI(普通的香草表)。

从概念上讲,表格列出了残疾学生,在保存新姓名和电子邮件后,它应该更新已经显示的表格。

这是在 app.js 中:

app.controller('StudentCtrl', function($scope, Student){

      $scope.students = Student.query();

      $scope.addStudent = function() {
            var name = $scope.newName;
            var email = $scope.newEmail;

            var newStudent = Student.save({name: name, email: email});
            $scope.newName = '';
            $scope.email = '';
      }
});

这是我的 HTML:

<body>
<div id="mainContainer" ng-controller="StudentCtrl">
    <input type="search" id="studentSearchbox" ng-model="studentSearch"></input>
    <div id="studentsList">
        <table>
            <thead>
                <tr>
                    <th>Student Name</th>
                    <th>Student Email</th>
                    <th>Student ID</th>
                </tr>
            </thead>
            <tbody>
                    <tr ng-repeat="student in students | filter:studentSearch" ng-class-even="'even'" >
                        <td>{{student.name}}</td>
                        <td>{{student.email}}</td>
                        <td>{{student._id.$oid}}
                    </tr>
            </tbody>
        </table>
        <hr />
        <div id="addStudentDiv">
            <h2>Add Student</h2>
            <label ng-model="newStudent">{{newStudent.name}}</label>
            <br />
            <input type="text" placeholder="Firstname-Lastname" ng-model="newName">Student Name</input>
            <input type="email" placeholder="Email" ng-model="newEmail"></input>
            <button type="button" ng-click="addStudent()">Submit</button>
        </div>
    </div>
</div>
4

1 回答 1

0

不确定这是否是“角度”方式,但我的解决方案是把这个

$scope.students.push(newStudent);

var newStudent = Student.save({name: name, email: email});
于 2013-05-27T08:49:04.303 回答