Solved

Assigning values to array AngularJS, Javascript

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…
The viewer will learn how to count occurrences of each item in an array.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now