Solved

Assigning values to array AngularJS, Javascript

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

631 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