我想将 angularjs 中的 html 代码传递给温泉页面或将数组传递给温泉页面中的 js
i want to pass html code from angularjs to onsen page or pass an array to js in onsen page
这是我在 angular 控制器中的代码:
$scope.showClients='<table>';
for (var i = 0; i < data[0].nomBCL.length; i++)
{
$scope.showClients+='<tr><td>'+data[0].nomBCL[i]+'</td>';
$scope.showClients+='<td>'+data[0].tmsBCL[i]+'</td></tr>';
//// OR
//$scope.showClients+='<tr><td>'+data[0].nomBCL[i][0]+'</td>';
//$scope.showClients+='<td>'+data[0].nomBCL[i][1]+'</td></tr>';
}
$scope.showClients+='</table>';
angular ng-bind-html 不起作用
我想到的另一个想法是将数据作为二维数组通过 $scope 传递到 html 页面,然后将 'for' 或 'while' 放入 javascript,但这都不起作用。
数据来自mysql数据库
"does not work" 通常是对问题的错误描述。
你得到的结果是空白吗?在那种情况下,Angular 可能不想显示 html,因为它被认为是不安全的。
您必须使用 $sce 服务来确保您的 html 字符串安全:
首先将服务注入您的控制器:
myApp.controller('myCtrl', ['$scope', '$sce', function($scope, $sce) {
...
}
确保您的字符串 html 安全:
$scope.showClientsSafe = $sce.trustAsHtml($scope.showClients);
现在使用 "showClientsSafe" 而不是 "showClients"。
我认为每次将 "showClients" 分配给 "showClientsSafe" 时都必须调用 trustAsHtml 函数。
这是我在 angular 控制器中的代码:
$scope.showClients='<table>';
for (var i = 0; i < data[0].nomBCL.length; i++)
{
$scope.showClients+='<tr><td>'+data[0].nomBCL[i]+'</td>';
$scope.showClients+='<td>'+data[0].tmsBCL[i]+'</td></tr>';
//// OR
//$scope.showClients+='<tr><td>'+data[0].nomBCL[i][0]+'</td>';
//$scope.showClients+='<td>'+data[0].nomBCL[i][1]+'</td></tr>';
}
$scope.showClients+='</table>';
angular ng-bind-html 不起作用
我想到的另一个想法是将数据作为二维数组通过 $scope 传递到 html 页面,然后将 'for' 或 'while' 放入 javascript,但这都不起作用。
数据来自mysql数据库
"does not work" 通常是对问题的错误描述。
你得到的结果是空白吗?在那种情况下,Angular 可能不想显示 html,因为它被认为是不安全的。
您必须使用 $sce 服务来确保您的 html 字符串安全:
首先将服务注入您的控制器:
myApp.controller('myCtrl', ['$scope', '$sce', function($scope, $sce) {
...
}
确保您的字符串 html 安全:
$scope.showClientsSafe = $sce.trustAsHtml($scope.showClients);
现在使用 "showClientsSafe" 而不是 "showClients"。
我认为每次将 "showClients" 分配给 "showClientsSafe" 时都必须调用 trustAsHtml 函数。