【发布时间】:2018-01-29 22:56:23
【问题描述】:
我在使用 Angular.JS 将我的 JSON 数据传输到 HTML 时遇到问题,我正在学习编程课程,这是我遇到的一个作者似乎没有遇到的问题,有人可以帮忙吗?
我正确链接了角度,我正确添加了应用程序,它应该可以工作,有什么想法吗?
https://pastebin.com/K4HR23Tk - HTML
<html ng-app="myQuiz">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Your Knowledge: Saturn</title>
<link rel="stylesheet" type="text/css" href="css/quiz.css">
</head>
<body>
<div id="myQuiz" ng-controller="QuizController">
<h1>Test Your Knowledge: <span>Saturn</span></h1>
<div class="progress"> {{totalQuestions}} </div>
https://pastebin.com/5emA4016-JS
(function(){
var app = angular.module('myQuiz',[]);
app.controller('QuizController',['$scope', '$http', '$sce', function($scope,$http,$sce){
$scope.score = 0;
$scope.activeQuestion = -1;
$scope.activeQuestionAnswered = 0;
$scope.percentage = 0;
$http.get('quiz_data.json').then(function(quizData){
$scope.myQuestions = quizData.data;
$scope.totalQuestions = $scope.myQuestions.length;
});
});
})();
【问题讨论】:
-
使用 jsfiddle 或 codepen 来分享你的代码。他们可以通过选择它作为选项来链接 Angular JS。
-
好的,我现在试着把我的代码放进去,这样我就可以得到一些帮助,谢谢。
标签: javascript html angularjs json