我試圖根據點擊的按鈕設置一個變量。AngularJS更改ng-repeat內的變量
這裏是我的代碼:
'use strict'
angular.module('myApp')
.controller('AlineacionCtrl', function ($scope, $meteor) {
$scope.activeIndex = {index: 0};
$meteor.subscribe('kits').then(function(){
$scope.kits = $meteor.collection(Kits, false);
$scope.activeCategory = $scope.kits[0].name;
console.log($scope.activeCategory);
$scope.log = function(){
console.log($scope.activeCategory);
};
});
});
。
<section layout="row" layout-align="center center" layout-wrap ng-init="activeIndex; activeCategory">
<md-button flex="auto" flex-sm="45" flex-xs="100" ng-repeat="kit in kits | orderBy: 'order'" ng-class="{active: (activeIndex.index == $index)}" class="md-raised">
<a href="" ng-click="activeIndex.index = $index; activeCategory = kit.name; log()" class="bold">{{kit.name}}</a>
</md-button>
</section>
ng-click="activeIndex.index = $index; activeCategory = kit.name"; log()
我正在嘗試設置activeCategory
爲當前點擊按鈕kit.name
但每次的log()
功能記錄的第一kit.name
並不會改變。
我在這裏做錯了什麼?
謝謝!
爲什麼log函數放在'$ meteor.subscribe'裏面? –
只是把它拿出來,仍然是相同的日誌。 –
它只是返回集合的'名稱',在這種情況下,每次我按下按鈕時,無論哪一個都是第一個。 –