我正在使用ng-init指令进行初始化。我有一个按钮(btnPrevious),它不应该在启动时显示,而只能在ng-click调用时显示。如何在隐藏按钮的情况下初始化应用程序,然后在ng-click上显示?
var MyApp = angular.module('MyApp', ['angular-loading-bar']);
MyApp.controller('MyController', function ($scope, $http, $rootScope) {
$scope.getFirstQuestion = function () {
$http.get('/URL')
.success(function (qst) {
$scope.question = qst;
})
.error(function (error) {
$scope.status = error.message;
console.log($scope.status);
});
}
$scope.getNextQuestion = function (p, r) {
//
}
$scope.getPreviousQuestion = function () {
//
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="MyApp" class="container">
<div ng-controller="MyController" ng-init="getFirstQuestion()">
<h3>{{question.Description}}</h3>
<ul>
<li ng-repeat="r in question.Answers">
<input type="button" id="{{r.Id}}" value="{{r.Description}}"
ng-click='getNextQuestion(question.Id, r.Id)' class="btn btn-default" />
</li>
</ul>
<input type="button" ng-click='getPreviousQuestion()' name="btnPrevious" value="Previous" class="btn btn-default" />
</div>
</div>