1

I am new to angular js, i wanted to assign the suncorp data which is equal to response into an array , what's wrong with the code? . is the result an array of data? . btw dont worry about the services its working the data is from an api (https://jobs.search.gov/jobs/search.json?query=nursing+jobs).

function TESTController($scope, testFac) {
    /* console.log("TESTControlleris now available.");*/
    $scope.data1= [];
    testFac.getData().then(function(response) {
    $scope.data1 = response.data;

          console.log("Data:",$scope.data1);
    })

2 Answers 2

1

if response.data is not an array, and you want the data in an array then, you need to push data to array using array push method;

function TESTController($scope, testFac) {
    /* console.log("TESTControlleris now available.");*/
    $scope.data1= [];
    testFac.getData().then(function(response) {
    $scope.data1.push(response.data);

          console.log("Data:",$scope.data1);
    })
Sign up to request clarification or add additional context in comments.

4 Comments

the data from the api is an array :)
if the response is an array, than you don't need to use push method.
Thank you Sir. I do really Salute to programmers or people from India. (bow)
What is the problem you facing ?
0

var app = angular.module("app",[]);
app.controller("postcontroller", function($scope, $http){
$scope.getAllProjects = function() {
        var url = 'https://reqres.in/api/products';
        $http.get(url).then(
            function(response) {
            $scope.projects = response.data.data;
            },
            function error(response) {
              $scope.postResultMessage = "Error with status: "
                  + response.statusText;
            });
      }
      $scope.getAllProjects(); 
 });
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
</head>
<body ng-app="app">
<div ng-controller="postcontroller">
<div class="panel-body">
    <div class="form-group">
      <label class="control-label col-sm-2" for="project">Project:</label>
      <div class="col-sm-5">
        <select id="projectSelector" class="form-control">
          <option id="id" ng-repeat="project in projects"
             value="{{project.id}}">{{project.name}}</option>
        </select>
      </div>
    </div>
  </div>
 </div>
</body>
</html>

Comments

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.