注入令牌不正确!预期的服务名称为字符串,得到函数($ scope,AllocateService,testService)

时间:2016-09-08 11:20:44

标签: angularjs json model-view-controller

请帮我纠正错误

myApp.controller('AllocateController', [ '$scope','AllocateService','testService',
  function ($scope, AllocateService, testService) {
    //code line
  },
  function ($scope, testService, AllocateService) {
    //code line
  }]);

2 个答案:

答案 0 :(得分:0)

详细代码

myApp.factory('testService', function ($http) {
    var fac = {};
    fac.GetLastContact = function () {

        return $http.get('/Data/PartsAvailable');

    }
    return fac;
});

myApp.factory('AllocateService', function ($http) {
    var fac = {};
    fac.SaveFormData = function (data) {
        var defer = $q.defer();
        $http({
            url: '/Data/LeaveReq',
            method: 'POST',
            data: JSON.stringify(data),
            headers: { 'content-type': 'application/json' }
        }).success(function (d) {
            // Success callback
            defer.resolve(d);
        }).error(function (e) {
            //Failed Callback
            alert('Error!');
            defer.reject(e);
        });
        return defer.promise;
    }
    return fac;
});

myApp.controller('AllocateController', [ '$scope', 'AllocateService','testService',
    function ($scope, AllocateService, testService ) {

        $scope.Allocate = null;
        testService.GetLastContact().then(function (d) {
            $scope.Allocate = d.data; // Success

        }, function () {
            alert('Failed'); // Failed
        });
    },
    function ($scope, testService, AllocateService) {
        $scope.submitText = "Save";
        $scope.submitted = false;
        $scope.message = '';
        $scope.isFormValid = false;
        $scope.User = {
            TaskName: '',
            ProductName: ''

        };

        $scope.$watch('Allocateform.$valid', function (newValue) {
            $scope.isFormValid = newValue;
        });
        //Save Data
        $scope.SaveData = function (data) {
            if ($scope.submitText == 'Save') {
                $scope.submitted = true;
                $scope.message = '';

                if ($scope.isFormValid) {
                    $scope.submitText = 'Please Wait...';
                    $scope.User = data;
                    testService.SaveFormData($scope.User).then(function (d) {
                        alert(d);
                        if (d == 'Success') {
                            //have to clear form here
                            ClearForm();
                        }
                        $scope.submitText = "Save";
                    });
                }
                else {
                    $scope.message = 'Please fill required fields value';
                }
            }
        }
        //Clear Form (reset)
        function ClearForm() {
            $scope.User = {};
            $scope.User.$setPristine(); //here f1 our form name
            $scope.submitted = false;
        }
    }]);

答案 1 :(得分:0)

您正在定义控制器功能两次。

WITH cte_1 AS (SELECT VALUE, VALUE-LEAD(VALUE) OVER(PARTITION BY DocNo ORDER BY DocNo) Result, Source1, Source2, LEAD(Source1) OVER(PARTITION BY DocNo ORDER BY DocNo) NxtSource1, LEAD(Source2) OVER(PARTITION BY DocNo ORDER BY DocNo) NxtSource2, DocNo FROM #myTable) SELECT Case WHEN (Source1=1 AND NxtSource1=1) AND (Source2=0 AND NxtSource2=1) THEN Result ELSE VALUE END as Value, Source1,Source2,DocNo FROM cte_1 WHERE (Source1<>1 OR source2 <>1) 期望一个数组带有引用可注入实体的字符串,最后一个数组成员定义控制器函数/类。

angular.controller()