Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想将html代码从angularjs传递到onsen页面,或者将数组传递到onsen页面中的js_Javascript_Jquery_Html_Angularjs_Onsen Ui - Fatal编程技术网

Javascript 我想将html代码从angularjs传递到onsen页面,或者将数组传递到onsen页面中的js

Javascript 我想将html代码从angularjs传递到onsen页面,或者将数组传递到onsen页面中的js,javascript,jquery,html,angularjs,onsen-ui,Javascript,Jquery,Html,Angularjs,Onsen Ui,以下是我在angular controller中的代码: $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

以下是我在angular controller中的代码:

$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>';
}
myApp.controller('myCtrl', ['$scope', '$sce', function($scope, $sce) {
   ...
}
$scope.showClients='';
对于(var i=0;i
$scope.showClients+=''

绑定html不起作用

我想到的另一个想法是将数据作为2d数组通过$scope传递到html页面,并将“for”或“while”放在javascript中,但这两种方法都不起作用

数据来自mysql数据库

“不工作”通常是对问题的错误描述

你得到一个空白的结果吗?在这种情况下,Angular可能不想显示html,因为它被认为是不安全的

您必须使用$sce服务使html字符串安全:

首先将服务注入控制器:

$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>';
}
myApp.controller('myCtrl', ['$scope', '$sce', function($scope, $sce) {
   ...
}
确保字符串html安全:

$scope.showClientsSafe = $sce.trustAsHtml($scope.showClients);
现在使用“showClientsSafe”而不是“showClients”


我认为每次您将“ShowClient”分配给“showClientsSafe”时,都必须调用trustAsHtml函数。

使用
ng repeat
。不要将模板和控制器混用。很少有你别无选择的情况。在这种情况下,我相信你是对的,混合是个坏主意。但是,如果您通过ajax从数据库加载一些内容,如文章或其他内容,则可能需要使用ng bind HTMLW,而不需要完整的控制器代码,很难知道是什么错误。您的控制器中是否包含了$http指令?是的,我想是这样。试试:yourApp.controller(“LogInController”、[“$scope”、“$sce”、“$http”、function($scope、$sce、$http)你是一个救世主……我对这一点很陌生,我尝试了将近两天来解决它。。。。