VSRSarma Chinta
VSRSarma Chinta

Reputation: 23

How to set object in Angular js model list object

I am new to angular js. I am trying to set a value in object in list object.

Model class
public class InfoModel{
    public List<TestInfo> testInfo;
    public void setTestInfo(List<TestInfo> testInfo){this.testInfo=testInfo;}
    public List getTestInfo(){return testInfo;}
    public int amount=0; //we have setters and getters for amount
}

TestInfoclass
public class TestInfo{
    public User user;
    public void setUser(User user){this.user=user;}
    public User getUser{return user;}
}

User object has name and id.

In angular controller
$scope.submitStatus = function(form1){
    $scope.infoModel.testInfo=[];
    var user; 
    if($scope.infoModel.amount<=6000){
       user = form1[0].user;
    } else {
       user = form1[1].user;
    } //Now I need to assign var user to TestInfo object at 0th location.
}

Please help in this. Thanks a lot for your help and time on this.

Thanks Rama

Upvotes: 0

Views: 611

Answers (1)

Tom Van Rossom
Tom Van Rossom

Reputation: 1470

Is this what you are looking for?

var testInfo = {user: user};
$scope.infoModel.testInfo.push(testInfo);

This creates a javascript object and add it to the list of testInfos.

Upvotes: 1

Related Questions