I have code like this:
You can better add the following table-html to your template like this:
<table>
<thead>
<tr>
<th>菜名</th><th>单价</th><th>份数</th><th>小计</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="id in obj">
<td>{{name}}</td>
<td>{{price}}</td>
<td>{{num}}</td>
<td>{{total}}</td>
</tr>
</tbody>
</table>
Ng-Repeat will render the necesarry table rows for every item in your obj variable. After that you will need to define $scope.obj
in your controller since your angular app will look for that. I think that just definig var obj
is not working, but I have never used it that way.
This won't work. Instead just use Angular ng-repeat inside the template to generate your table.
I assumed you are using the ui-bootstrap-modal (text/ng-template) thus you are able to pass the object you want to use into the controller
of your modal by using the resolve
functionality.
var modalInstance = $modal.open({
animation: true,
templateUrl: 'xml-feed.html',
controller: function($modalInstance, detail) {
this.detail = detail;
this.close= function () {
$modalInstance.close();
}
},
controllerAs: 'myModal',
size: 'lg',
resolve: {
detail: function () {
//here you will need to return a reference
//I assumed the modal is opened in a controller
//that already has the detail object on its scope
return $scope.detail;
}
}
});
And in your modals HTML you can simple use the object in an angular way.
<table>
<thead>
<tr>
<th>菜名</th><th>单价</th><th>份数</th><th>小计</th>
</tr>
</thead>
<tbody>
<tr><td>{{myModal.detail}}</td><tr> //do what you need with this object
</tbody>
</table>
P.S. I used the controllerAs syntax in the modal.