【发布时间】:2016-11-28 18:43:03
【问题描述】:
我已经使用 Moodle WebService 开发了一个 AngularJS Moodle webapp,我正在尝试展示 Moodle eLearning 中的一个测验。
我可以使用$http. 解答所有问题。现在的问题是,当我收到问题时,每个问题都带有这样的 HTML 代码:
我正在使用此控制器来获取 响应 (url5)
app.controller('quizCtrl', function($rootScope, $scope, $http) {
url4 = concatUrl + 'mod_quiz_start_attempt' + '&quizid=2';
$http.get(url4).then(function (response) {
//console.log(response.data);
})
url5 = concatUrl + 'mod_quiz_get_attempt_data' + '&attemptid=7&page=0';
$http.get(url5).then(function (response) {
console.log(response.data);
$scope.questions = response.data.questions;
})
})
当我使用以下代码在 HTML 中显示问题时,我将 HTML 代码作为字符串获取并尝试使用 ng-bind-html 但出现错误。
<div role="main" id="main" class="ui-content scroll" ng-app="mainApp">
<div data-role="content" class="pane" id="">
<div class="page-wrap scroll" ng-controller="quizCtrl">
<div ng-repeat="question in questions | orderBy : 'question.number'" id="{{question.number}}">
<div>
<!--{{question.html}}<br /><br />-->
<p ng-bind-html="question.html"> </p><br /><br />
</div>
</div>
</div>
</div>
另外,我尝试过:
JSON.stringify
angular.fromJson(json);
当我使用这行 {{question.html}}<br /><br /> 时,我得到了这个:
感谢你们的帮助!
【问题讨论】:
-
如果你使用 'angular.js' 而不是 'angular.min.js' 你会看到错误文本,而不是链接。 :)
标签: javascript jquery html angularjs json