如何使用angular.js将javascript数组变量值传递给html
我是新手 我想通过填充javascript数组变量中的值来创建一个表。 我在变量中创建并输入了如下值如何使用angular.js将javascript数组变量值传递给html,javascript,angularjs,templating,Javascript,Angularjs,Templating,我是新手 我想通过填充javascript数组变量中的值来创建一个表。 我在变量中创建并输入了如下值 var result=[]; //some loop. Just demonstrating that there are multiple values of id and text result.push( { "id":obj["id"],
var result=[];
//some loop. Just demonstrating that there are multiple values of id and text
result.push(
{
"id":obj["id"],
"text":obj["text"],
}
);
我希望html中的每个id和结果变量中的文本都有一个新行
<table>
<tr><td>id</td><td>text</td></tr>
<table>
idtext
使用angular.js做这件事的方法是什么。找到了答案。如果有人需要,就把它放在这里 Javascript代码:
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代码
<div ng-controller="controller">
<table ng-repeat="result in results">
<tr><td>{{result.id}}</td><td>{{result.text}}</td></tr>
<table>
</div>
{{result.id}{{result.text}
我要看看这是否有用