-1

How to send this data in AngularJS. (It's a multiple array in a multiple array which need to send on one Object)

[{
"working_day":"sunday",
"from_time":{"hour":"9","min":"30"},
"to_time":{"hour":"6","min":"30"}
},{
"working_day":"monday",
"from_time":{"hour":"9","min":"30"},
"to_time":{"hour":"6","min":"30"}... and so on for other week days
}]

I am trying to send data like this in an API and I am new to AngularJs, so please tell me how can I make this data through HTML at runtime?

            $scope.schedule = []; // Hard coded value
            $scope.week = {};
            $scope.week.working_day = "Sunday";
            $scope.week.from_time = {};
            $scope.week.from_time.min = "10:00";
            $scope.week.from_time.max = "5:00";
            $scope.week.to_time = {};
            $scope.week.to_time.min = "2:10";
            $scope.week.to_time.max = "8:00";

    var dataParam =  {
                        "prefix":$scope.data1.prefix,
                        "first_name":$scope.data1.first_name,
                        "password":$scope.data1.password,
                        "last_name":$scope.data1.last_name,
                        "email_id":$scope.data1.email_id,
                        "mobile_number":$scope.data1.mobile_number,
                        "roleCode":[$scope.data1.roleCode],
                        "role":[$scope.data1.role],
                        "Schedule":angular.toJson($scope.schedule.push($scope.week))

                      }
 console.log(angular.toJson(dataParam));
            /* $http({
            url:  "/here",
            method: "POST",
            headers :{'Content-Type': 'application/json','Accept': 'application/json' },
            data: dataParam
            }) .success(function(response) {
                if(response.status_code=="success")
                {
                    $scope.successmsg = response.status_message;

            console.log(angular.toJson(response));
            $state.go('dashboard.setting.user', {'user': $scope.viewUser});
                }
                else {

              $scope.successmsg = response.status_code;
                }

            });  */

};

for now i just need to send this data format with angular js, please suggest

this is what i am doing in angular by "hard code" i need to send this data in angular js, how can i do that?

now please help me with html code of angular to send that hard coded value into runtime value by user

13
  • you want to send data from angularjs or want to display this data using angularjs? Commented Sep 6, 2016 at 9:25
  • send and fetch accordingly Commented Sep 6, 2016 at 9:26
  • Do you want to display this data in HTML also ? Commented Sep 6, 2016 at 9:27
  • yes... i do want to fetch also and display it html Commented Sep 6, 2016 at 9:29
  • You should use $http service DOC Commented Sep 6, 2016 at 9:29

1 Answer 1

0

Have an array

$scope.schedule = [];

Create an object with your Json keys

$scope.week = {};
$scope.week.working_day = "";
$scope.week.from_time = {};
$scope.week.from_time.min = "";
$scope.week.from_time.max = "";
$scope.week.to_time = {};
$scope.week.to_time.min = "";
$scope.week.to_time.max = "";

Push it into array

$scope.schedule.push($scope.week);
Sign up to request clarification or add additional context in comments.

5 Comments

it is only returning 1
again returning 1
send the entire array, returning 1 means..! show me how you call the API from Js.
this is simply what i printing on console nd getting array length not the value $scope.schedule = []; $scope.week = {}; $scope.week.working_day = "Sunday"; $scope.week.from_time = {}; $scope.week.from_time.min = "10:00"; $scope.week.from_time.max = "5:00"; $scope.week.to_time = {}; $scope.week.to_time.min = "2:10"; $scope.week.to_time.max = "8:00"; var dataParam = { "Schedule":$scope.schedule.push($scope.week) // here schedule.push is an array } console.log(angular.toJson(dataParam));
change this "Schedule":angular.toJson($scope.schedule.push($scope.week)) to "Schedule":angular.toJson($scope.schedule)

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.