我有以下代碼
var myapp = angular.module('myapp', []);
myapp.controller('FirstCtrl', function ($scope) {
$scope.people = [
{ id: 1, first: 'John', last: 'Rambo' },
{ id: 2, first: 'Rocky', last: 'Balboa' },
{ id: 3, first: 'John', last: 'Kimble' },
{ id: 4, first: 'Ben', last: 'Richards' }
];
$scope.updateByReference = function() {
var tst = $scope.people;
tst = [];
console.log($scope.people);
}
});
我期望$ scope.people有一個新的價值和空數組對象,但它沒有被更新更新,這裏是小提琴 http://jsfiddle.net/9fR23/409/
那麼,怎樣才能達到我所期望的行爲? – Petran
@Petran更新 –