控制器没有看到功能

时间:2017-07-23 19:26:30

标签: angularjs

这是我的services.js

(function () {   
var app = angular.module('crmService', []);

app.factory('timeline', ['$http', function ($http) {
        var _addTimelineEvent = function (clientId, eventData) {
            callback = callback || function () {};

            return $http({
                method: 'POST',
                url: '/simple_crm/web/api.php/client/' + clientId + '/timeline',
                data: eventData
            });
        };

        return {
            addTimelineEvent: _addTimelineEvent
        };
    }]);
})();

这是我的控制者:

app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {

    $routeProvider
            .when('/clients', {
                controller: 'ClientsListCtrl',
                templateUrl: 'views/clients-list.html'
            })
            .when('/clients/:clientId', {
                controller: 'ClientDetailCtrl',
                templateUrl: 'views/client-details.html'
            })
            .otherwise({
                redirectTo: '/clients'
            });

    $locationProvider.html5Mode(true).hashPrefix('');
}]);
app.controller('ClientDetailCtrl', ['$scope', 'clients', 'users', 'sectors', '$routeParams', '$timeout', 'timeline',
    function ($scope, clients, users, sectors, $routeParams, $timeout, timeline) {

        $scope.client = {};
        $scope.timeline = []; 
        $scope.timelineEvent = {};
        $scope.eventTypes = timeline.getEventsType();

        $scope.saveClientData = function () {
            if ($scope.clientForm.$invalid)
                return;

            clients.updateClient($scope.client.id, $scope.client)
                    .then(
                            function () {
                                //messeges to user
                            },
                            function (error) {
                                console.log(error);
                            }
                    );
        };

        $scope.addEvent = function () {

            if ($scope.eventForm.$invalid)
                return;

            timeline.addTimelineEvent($scope.client.id, $scope.timelineEvent)
                    .then(
                            function () {
                                //messeges to user

                            },
                            function (error){
                                console.log(error);
                            });

        };

    }]);
})();

我收到错误:

  

TypeError timeline.addTimelineEvent不是函数

我无法理解为什么上面的函数工作正常,但timeline.addTimelineEvent实际上是相同的,报告错误。 有什么建议吗?

我添加了所有代码以获得更好的视图:

Full code

时间轴功能位于app文件的末尾

0 个答案:

没有答案