我继续得到TypeError:v2.CurrentTaskForce不是一个函数

时间:2015-11-25 06:02:31

标签: angularjs typeerror

页面的左侧显示任务组列表。 点击列表项目相关数据将显示在右侧。 当我点击列表项时,第一次它工作正常。它将任务组名称显示为右侧面板中的标题。当我点击另一个列表项时,它会给出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>

2 个答案:

答案 0 :(得分:0)

将项目复制到CurrentTask force而不是

$scope.CurrentTaskForce = item;

我用过

angular.copy(item, $scope.CurrentTaskForce);

答案 1 :(得分:0)

正在发生这种情况,因为CurrentTaskForce被定义为同一控制器中的函数和变量。请使用其他名称。