0

Thanks for all your input, but now I have more or less a similar problem, I have the data that needs to be stored in sql-server database, when I try to post it the data does not get written. Is my code structure correct?

self.CurrentDowntimeEvent = {
        method: 'POST'
        , url: 'someurl/test'
        , data: {
          DepartmentId: cookie
        , CategoryId: -1
        , Comment: ""
        , DowntimeStart: "2014-07-07T10:00:00"
        , DowntimeEnd: null
        }
        , headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
    }).success(function (data) {
        console.log(data);
    }).error(function (data) {
    });

1 Answer 1

1

$http is a service which should be injected into the controller, so you shouldn't need self. to reference it:

self.RecordsSave = function () {
    for (var i = 0; i < self.Employees.length; i++) {
        var employee = self.Employees[i];
        var params = {
            CompanyNumber: employee.ClockNumber,
            Department: employee.DepartmentID,
            Present: employee.Present,
            Reason: employee.AbsentCode
        };
        $http.post(SAVE_EMPLOYEERECORDS, {
            params: params
        }).success(function (data) {
            alert("testing");

        });
    }
};
Sign up to request clarification or add additional context in comments.

6 Comments

what is self? why it is used?
Generally self is used as a reference to a parent object, so you know what object it references instead of depending on this e.g. (function() { var self = this; var internalFunction = function() { self.hello(); }; }()); - I'm assuming that's what it is in this case
But how would self.RecordsSave get called?
@micronyks Could be anything - inside a controller, service, or something else. Hard to tell without more context
@user, @ RGraham .How can you call RecordsSave() without using '$scope'. shouldn't it be $scope.RecordsSave=function()?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.