【发布时间】:2017-07-06 08:43:04
【问题描述】:
(function() {
'use strict';
angular
.module('app.interview', [])
.controller('InterviewController', InterviewController)
.factory('Interview', Interview);
InterviewController.$inject = ['$scope', 'Interview'];
Interview.$inject = ['$http'];
function Interview($http) {
var service = {};
service.fetchQuestion = fetchQuestion;
return service;
function fetchQuestion() {
return $http.get('/app/interview/questions.json');
}
}
})();
<div class="ad-container">
<h1 class="text-center headtext">Interview Questions</h1>
<form name="interviewForm">
<p></p>
</form>
</div>
这是我的 json
{
"Q1": "What is a pointer on pointer?",
"Q2": "Write about yourself?",
"Q3": "write a program to find multiplication of two number?",
"Q4": "write a program to find addition of two number?",
"Q5": "write a program to find subtraction of two number?",
"Q6": "write a program to find percentage?",
"Q7": "write a program to find addition of two number?",
"Q8": "write a program to find addition of two number?"
}
如何从 json 中获取单个问题并在 html 中显示?
【问题讨论】:
-
您可以使用 ng-repeat 获取问题并将其显示在 UI 上
-
您要显示单个问题还是所有问题?另外,你也可以发布你的 InterviewController 吗?
-
想要显示一个问题并且控制器在那里,即 InterviewController.$inject = ['$scope', 'Interview'];
-
哪一个问题?您的问题不具体。
-
在使用 ng-repeat 时对 1 个问题使用分页和限制过滤器