Solved

Assigning values to array AngularJS, Javascript

Posted on 2014-09-19
3
300 Views
Last Modified: 2014-09-22
Please look at the controller. All I want is store $scope.subDetailsList array values into $scope.items. How can I do that?

function subController($scope, $location, $routeParams, $http, $modal, $log) {
    $scope.subID = $routeParams.subID;

    $http({
        url: 'http://smothing',
        method: "GET", params: {
            SubID: $scope.subID
        }
    }
    ).success(function (data) {
        $scope.subDetailsList = [];
        angular.forEach(data, function (Result) {
            $scope.subDetailsList.push(Result);
        }
        );
    }
    );

    //$scope.items = $scope.subDetailsList;
    $scope.items = ['item1', 'item2'];
	};

Open in new window

0
Comment
Question by:rbhargaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40333931
Try this :
function subController($scope, $location, $routeParams, $http, $modal, $log, DetailList) {
    
    $scope.subID = $routeParams.subID;


    //$scope.items = $scope.subDetailsList;
    $scope.items = ['item1', 'item2'];

    DetailList.get($scope.subID).then(function(items) {
        $scope.items.push(items);
    });

};

myApp.factory("DetailList", ["$http", "$q", function($http, $q) {
    return {
        get: function(theSubID) {
            var deferred = $q.defer();
            $http.get('http://smothing', { SubID: theSubID })
            .success(function (data) {
                deferred.resolve(data);
            });
            return deferred.promise;
        }
    }
}]);

Open in new window

0
 

Author Comment

by:rbhargaw
ID: 40333942
I will check back on Monday, Thanks!
0
 

Author Comment

by:rbhargaw
ID: 40337592
Thanks..this worked!
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question