Solved

Assigning values to array AngularJS, Javascript

Posted on 2014-09-19
3
288 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
  • 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

839 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