我需要使用angular.js将一些HTML部分绑定到视图中。
为time.html:
<table class="table table-bordered table-striped table-hover" id="dataTable">
<tr>
<td width="100" align="center">Time <i class="fa fa-long-arrow-right"></i>
<BR>Day <i class="fa fa-long-arrow-down"></i>
</td>
<td width="100" align="center" ng-repeat="hour in hours" ng-bind="hour.time_slot"></td>
</tr>
<tbody id="detailsstockid" >
//Here my data will bind
</tbody>
</table>
控制器:
$http({
method:'POST',
url:"php/hodtime/getTimeTableData.php",
data:userdata,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('response',response);
$("#detailsstockid").html(response.data);
},function errorCallback(response) {
});
response.data
在控制台中输出此内容:
<tr>
<td width="100" align="center" style=" vertical-align:middle">Monday</td>
<td width="100" align="center" style="padding:0px;">
<table style="margin:0px; padding:0px; width:100%">
<tr>
<td><input type="text" name="itemname" id="coursemname" class="form-control" placeholder="Add sub name" readonly value="Mechanics of Solids" id="30" ></td>
</tr>
<tr>
<td><input type="text" name="itemname" class="form-control" placeholder="Add fac name" readonly value="" id="" ></td>
</tr>
</td>
</table>
</td>
<td width="100" align="center" style="padding:0px;" >
<table style="margin:0px; padding:0px; width:100%">
<tr>
<td> <input type="text" name="itemname" id="coursemname" class="form-control" placeholder="Add sub name" readonly value="Engineering Materials" id="31" ></td>
</tr>
<tr>
<td><input type="text" name="itemname" class="form-control" placeholder="Add fac name" readonly value="" id="" ></td>
</tr>
</td>
我无法在我的视图中显示上述HTML输出。
答案 0 :(得分:0)
在您的控制器中将response.data绑定到范围变量。 更清楚:
在您的控制器中:
$http({
method:'POST',
url:"php/hodtime/getTimeTableData.php",
data:userdata,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
console.log('response',response);
$scope.variableName = response.data;
},function errorCallback(response) {
});
在你的html使用中
<tbody ng-bind-html="variableName"></html>
在循环中,它将使用响应数据创建尽可能多的tbody,循环将运行多次