嗨,朋友我是新角度和陷入創建一個$watch
功能的例子卡住。我只是想將數據推送到現有的模態(json數據)中,模型中的變化將反映到view
中。請檢查我下面的代碼或檢查fiddle here
SCRIPT
var list = [{
name: 'Jon',
joining_date:'2015-10-23',
age: 23
},
{
name:'Viki',
joining_date:'2015-01-24',
age: 20
},
{
name: 'Abc',
joining_date:'2015-10-25',
age: 43
},
{
name: 'XYZ',
joining_date:'2015-10-21',
age: 21
}];
var empApp = angular.module('emp-list', []);
empApp.controller('emp-table',function($scope){
$scope.data = list;
$scope.dateFormate = function(joinDate){
return new Date(joinDate)
}
// PUSHING DATA IN EXISTING MODAL
setInterval(function(){
$scope.data.push({name: 'XYZ', joining_date:'2015-10-21',age: 21})
}, 1000);
// USING $WATCH FUNCTION
$scope.$watch('data');
})