我有一個元素列表,我想要摺疊到一個點擊一個選定的元素。我無法讓控制器上的代碼刷新列表。我究竟做錯了什麼?我認爲改變$範圍將使視圖重新加載。控制器沒有重新加載更改後的視圖
我通過更改視圖中引用的$ scope變量來使其工作。所以我的猜測是,視圖上引用的變量的處理方式與其他$ scope屬性不同。是對的嗎?
AptListCtrl = ($scope) ->
console.log apt_selected
if $scope.apt_selected?
$scope.apts = [$scope.apt_selected]
else
$scope.apts = apts
$scope.aptClick = ($event, apt) ->
if $scope.apt_selected?
if $scope.apt_selected is apt
$scope.apt_selected = null
else
$scope.apt_selected = apt
else
$scope.apt_selected = apt
$('#selected_apt').html('Selected: ' + apt.title)
$scope.$watch('apt_selected', (newv, oldv, scope)->
console.log 'new'
console.log newv
console.log 'old'
console.log oldv
)
$scope.$digest()
<ul class="list-group" ng-controller = "AptListCtrl">
<li class="list-group-item" ng-repeat = "apt in apts"
ng-click="aptClick($event, apt)" ng-model = "apt_selected">
<a href="#">{{apt.marker_text}}</a>
</li>
</ul>