納克重複內我有一個路由器:
.config(['$routeProvider',function($routeProvider) {
$routeProvider
.when('/allbooks', {
templateUrl: 'find/showAllMy.html',
controller: 'controlador'
}).when('/mybooks', {
templateUrl: 'find/showAllMy.html',
controller: 'controlador'
})
.when('/',{
templateUrl: 'find/inputbook.html',
controller:'controlador'
})
}]);
視圖文件 「showAllMy.html」:
<div id='containerMyBooks' ng-init='MyRequests=0; RequestsForMe=0; '>
<center><h3>{{titleMyAll}}</h3></center>
<div id='containerbuttonsrequest'>
<button class='waves-effect waves-light btn'>Your Trade Request {{MyRequests}} </button>
<button class='waves-effect waves-light btn'>Trade Request for you {{RequestsForMe}}</button>
</div>
<ul ng-repeat='b in Books' ng-init='tradeLink[$index]=true'>
<li class='styleLi'>
<a class='stylelinktrade' ng-show='tradeLink[$index]' href='/#/{{titleMyAll}}' ng-click="trade('yes',$index)"><img class="styleimgtrade" src='../images/trade.png'>trade!</a>
<a class='stylelinktrade' ng-hide='tradeLink[$index]' href='/#/{{titleMyAll}}' ng-click="trade('no',$index)"><img class="styleimgtrade" src='../images/trade.png'>Cancel trade</a>
<img class='styleimgbook' src={{b.img}}>
</li>
</ul>
</div>
而這種邏輯在我的控制器:
$scope.trade = function(yesNo, index) {
if (yesNo === 'yes') {
$scope.MyRequests = $scope.MyRequests + 1;
} else {
$scope.MyRequests = $scope.MyRequests - 1;
}
console.log('log' + $scope.tradeLink[index]);
// $scope.tradeLink[0]=!$scope.tradeLink[0];
}
,但我似乎無法得到從視圖訪問$ scope.tradeLink [指數],相反,我得到一個錯誤說「無法讀取正確ty 1未定義。「
我該如何解決這個問題?
定義數組$ scope.tradeLink在哪裏?你能否包含一個內容的例子? – jbrown