Я новичок в angularjs, и я делаю небольшое приложение для викторины.Мой код angularjs:
var app = angular.module('myApp', []);
app.config(['$qProvider', function ($qProvider) {
$qProvider.errorOnUnhandledRejections(false);
}]);
app.controller('myctrl', ['$scope','$http',function($scope, $http) {
$scope.ques="";
$scope.data={
fd: true,
sd: false
};
$scope.show=true;
$scope.quiznum=function(quizno){
$scope.quiz=quizno;
$scope.myfunc();
}
$scope.myfunc=function(){
var url="http://localhost:3000/quizzes/";
console.log($scope.count);
$http.post(url,{'quizno':$scope.quiz,'question':++$scope.count})
.then(function(response) {
if(response.data.status=="ongoing"){
$scope.data={
fd: false,
sd: true
};
$scope.ques = response.data.ques;
console.log($scope.ques);
$scope.show=true;
}
else{
$scope.data={
fd: false,
sd: true
};
$scope.ques = response.data.status;
$scope.show=false;
}
});
}
}]);
app.directive("secondDirective", function() {
return {
templateUrl : "maincontent.html",
controller: "myctrl"
};
});
Файл maincontent.html:
<div ng-controller="myctrl" style="position: relative;top: 10px;left: 40%;">
<h3>{{ques}}</h3><br></br>
<button ng-click="myfunc()" ng-show="show">Next question</button>
</div>
Первый файл, который будет отображаться:
<body ng-app="myApp">
<div ng-controller="myctrl">
<first-directive ng-show="data.fd"></first-directive>
<second-directive ng-show="data.sd" ng-init="quiz=0;count=0"></second-directive>
</div>
</body>
Когда пользователь нажимает на любую из ссылок в предоставленной викторине, он / она переходит к одному из вопросов этой викторины.Но проблема в том, что, хотя я получаю первый вопрос в ответ от сервера, он не виден на странице, т. Е. Тег h3 в файле maincontent остается пустым.Но эта проблема происходит только с первым вопросом любой викторины.После этого все вопросы видны.Я перепробовал все, что знаю, но это не работает.Пожалуйста, помогите !!