Solved

Assigning values to array AngularJS, Javascript

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Performance for Office 365 6 48
Wordpress Taxonomy 2 28
javascript: add id amounts 5 47
How do I pull the base url for use in html links 7 23
This article will show, step by step, how to integrate R code into a R Sweave document
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

773 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