2017-04-10 5 views
-2

私はng-repeatを使用しています。新しい要件は新しい行です。新しい行をng-repeatで追加する他の関数

<span ng-repeat="sal in studentAttendanceList"> 
 
       {{sal.name}}  {{sal.class}}  {{sal.rolenumber}} 
 
</span>

controller.js

var studentList = Firebase.get('studentAttendanceList', 'name', $stateParams.chatId); 
 
studentList.$loaded().then(function() { 
 
    $ionicScrollDelegate.scrollBottom(true); 
 
    $scope.studentAttendanceList = studentList; 
 
}); 
 
$scope.studentAttendanceListalert = function() { 
 
    alert(add new enter); 
 
}

追加新しい入力するアラートが起動した場合。それはangularjsでどのように動作するのですか?

+0

を監視するために、時計を使っ追加するたびに表示したい場合。 'studentAttendanceList'が実行されたら' ng-repeat'に新しい行を追加する必要がありますか? –

+0

いいえ新しい行が表示されてもアラートの新しい行が追加された場合 –

+1

DBからデータを取得しています。 DBからデータを取得したら、各レコードごとにアラートを表示する必要があります –

答えて

2

アラートに新しい行が、その後の質問は不明であるが変化

$scope.$wacth('studentAttendanceList',function(oldVal,newVal){ 
if($scope.studentAttendanceList && $scope.studentAttendanceList.lenght > 0){ 
    if(newVal.length > oldVal.length){ 
    alert("new row added ") 
    } 
} 
}) 
+0

どこでoldvalueとnewvalueを取得するのですか? –

+0

がデフォルトで、watchはこれらのパラメータを渡します。彼らについて心配する必要はありません。基本的に変更された値と以前の値を渡しています。アプリケーションのロード時に –

+0

がこのエラーに遭遇しました。TypeError:未定義のプロパティ 'length'を読み取ることができません。 –

2
$scope.$watchCollection('studentAttendanceList',function(oldVal,newVal){ 
if($scope.studentAttendanceList && $scope.studentAttendanceList.lenght > 0){if(newVal.length > oldVal.length){ alert("new row added ")}}}) 
関連する問題