0

I am new to angular.js

I want to create a table by populating values from a javascript array variable. I created and entered values in my variable like this

        var result=[];    

        //some loop. Just demonstrating that there are multiple values of id and text
        result.push(
            {
                "id":obj["id"],                
                "text":obj["text"],
            }
        );

I want a new row for each id and text from result variable in html

<table>
<tr><td>id</td><td>text</td></tr>
<table>

What is way to do this using angular.js.

1

1 Answer 1

2

Figured it out. Putting it here if anyone needs it.

Javascript code:

function controller($scope, $http) {

    $scope.results=[];
    $http.get(url).success(function (data) {

        $.each(data, function () {
            var obj = data;
            console.log(obj);
            $scope.results.push(
                {
                    "id": obj["obj_id"],                    
                    "text": obj["text"]
                }
            );


        });
    });


}

html code

<div  ng-controller="controller">
    <table ng-repeat="result in results">
    <tr><td>{{result.id}}</td><td>{{result.text}}</td></tr>
    <table>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.