【问题标题】:Input can not be read | Angularfire + Firebase无法读取输入 | Angularfire + Firebase
【发布时间】:2014-05-02 00:34:37
【问题描述】:

所以,我在有角度的重复项目中有一个选择输入。我想使用一个按钮将房间分配给一个人。以及维护一个人是否选择了房间,它会显示它已经在选择输入中分配。

这是我的 Firebase 数据:

{
  "-JLtuRmYiTDLTnZPj" : {
    "last_name" : "NameOne",
    "person_id" : 1,
    "is_in" : false
  },
  "-JLtuRBlyWhHV28zd" : {
    "last_name" : "NameTwo",
    "person_id" : 2,
    "is_in" : false
  },
  "-JLtuQxlMn25APuKT" : {
    "last_name" : "NameThree",
    "person_id" : 3,
    "is_in" : false
  }
}

这是我的代码:

<table>
    <tbody>
      <tr ng-repeat="(name, person) in people | orderBy: 'doctor_id'" ng-model="person">
        <td>{{person.person_id}}</td>
        <td>{{person.last_name}}</td>
        <td><strong>{{person.is_in}}</strong></td>
        <td>Assign Rooms: <select multiple class="form-control" ng-model="person.room_id" ng-options="r.room_id as r.name for (key, r) in rooms"></select></td>
        <td><button type="button" href="" class="btn btn-primary" ng-click="assignRooms(name)">Assign Rooms</button></td>
      </tr>
    </tbody>
</table>

最后是我的 JS:

angular.module('app', ['ngRoute', 'firebase']);

$scope.people = $firebase(new Firebase("https://<FB-NAME>.firebaseio.com/dev/0/people"));
$scope.rooms = $firebase(new Firebase("https://<FB-NAME>.firebaseio.com/dev/0/rooms"));

//Assigns Rooms to each doctor.
$scope.assignRooms = function(name) {

    $scope.people.$child(name).$update({
        "room_id": $scope.person.room_id,
        "is_in": true
        });     
}

应用程序被正确调用。当我使用 Angular JS Batarang 时,我可以看到范围。当我单击分配房间按钮时,我收到错误:

无法读取未定义的属性“room_id”

来自:$scope.person.room_id。

我确信我很明显错过了一些东西。但非常感谢任何帮助。

谢谢!

【问题讨论】:

    标签: javascript angularjs firebase angularfire


    【解决方案1】:

    您需要使用person。您无法访问函数内的 ng-repeat 范围。

    <td>
        <button type="button" 
                href="" 
                class="btn btn-primary" 
                ng-click="assignRooms(name,person)">Assign Rooms</button>
    </td>
    

    $scope.assignRooms = function(name, person) {$scope.assignRooms = function(name) {
    
        $scope.people.$child(name).$update({
        "room_id": person.room_id,
        "is_in": true
        });     
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      • 2021-11-11
      相关资源
      最近更新 更多