2015-11-25 58 views
0

頁面左手邊顯示的是任務組的列表 點擊列表項右邊會顯示相關數據。 當我點擊列表項時,第一次可以正常工作..它會在右側面板中顯示任務組名稱作爲標題。當我點擊另一個列表項它給類型錯誤:v2.CurrentTaskForce不是一個函數我繼續得到TypeError:v2.CurrentTaskForce不是函數

var VirtualDir = GetVirtualDirectory(); 

    angular.module('MyApp',[]) 
    .controller('TaskForceController', function ($scope, TaskForceService) { // inject taskforce service 
     $scope.TaskForceList = null; 
     //$scope.CurrentTaskForce = {} 

     TaskForceService.GetTaskForceList().then(function (d) { 
      $scope.TaskForceList = d.data; 
     }, function() { 
      alert('failed'); 
     }); 

     $scope.CurrentTaskForce = function (item) { 
      angular.forEach($scope.TaskForceList, function (value, index) { 
       value.IsActive = false ; 
      }) 
      item.IsActive = true; 
      alert("s"); 
      $scope.CurrentTaskForce = item; 
     } 

    }) 
    .factory('TaskForceService', function ($http) { //here factory is created which is a populer way to create and configure services 
     var fac = {}; 
     fac.GetTaskForceList = function() { 
      return $http.get(VirtualDir + '/TaskForce/GetMyTaskForce/'); 
     } 
     return fac; 
    }); 



<div class="container-fluid" ng-controller="TaskForceController as tf"> 
    <div class="row"> 
     <div class="col-sm-3 col-md-2 sidebar"> 
      <ul class="nav nav-sidebar" > 
       <%--     <li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>--%> 
       <li ng-repeat="item in TaskForceList" ng-class="{active: item.IsActive == true}" ng-click="CurrentTaskForce(item)" ><a href="#" >{{item.TaskForce}}</a></li> 
      </ul> 
     </div> 
     <div class="col-sm-9 co-md-9" style="left:20%"> 
      <div class="panel panel-default" "> 
       <div class="panel-heading"> 
        <p class="panel-title">{{CurrentTaskForce.TaskForce}}</p> 
        <!--ng-repeat="curritem in CurrentTaskForce"--> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

回答

0

而複製項目CurrentTask力,而不是

$ scope.CurrentTaskForce =項目;

我用

angular.copy(項目,$ scope.CurrentTaskForce);