我有一个有角度的应用程序,我正在尝试刷新页面。我按照许多帖子中的建议尝试$route.reload()
。但我无法让它发挥作用。这是我的控制器:
var app = angular.module('StudentProgram', ['ngRoute', 'ui.bootstrap', 'jsonService']);
app.controller('mycontroller', function($route, RequirementsService, DegreesService, DegreeCategoriesService, DetailsService, ProgramsService, $scope, $modal, $log, $http) {
ProgramsService.getItems(function(data){
$scope.programs = data;
console.log(data);
});
$scope.$route = $route;
//$scope.programs=ProgramsService.query();
DegreeCategoriesService.query(function(data){
$scope.degreecategories = data;
console.log(data);
});
DetailsService.query(function(data){
$scope.details = data;
console.log(data);
});
RequirementsService.getRequirements(function(data){
$scope.requirements = data;
console.log(data);
});
$scope.addDegree = function(degree) {
var variablesToSend = {
"student": 2773951,
"credits_completed": 0,
"academic_program_gpa": 0,
"primary_program": false,
"academic_program": {
"id": degree.id,
"acad_program_category": degree.acad_program_category,
"acad_program_type": degree.acad_program_type,
"program_title": degree.program_title,
"required_credits": degree.required_credits,
"min_gpa": degree.min_gpa,
"description": "description of the course",
"colleges": degree.colleges
}
}
$http.post('/api/studentacademicprogram/', variablesToSend).then(function(response){
console.log(response);
alert('post added');
$route.reload();
}, function(response){
console.log(response);
alert('post not added');
});
};
这是我访问该功能的div:
<div ng-show="display.academicdegrees" class="col-lg-8 col-md-8 col-sm-8">
<div class="panel panel-warning list-group list-unstyled" data-spy="scroll" data-target="#panelcategory" data-offset="0" style="max-height:400px;overflow:auto;position:relative;">
<div class="panel-heading">
{% verbatim %}
<h3 class="panel-title">{{DegreeCategory}}</h3>
{% endverbatim %}
</div>
<li ng-repeat="degree in degrees" class="list-group-item">
{% verbatim %}<strong>{{degree.program_title}}</strong>{% endverbatim %}
<p>{% verbatim %} {{degree.description}}</p>
<span ng-repeat="college in degree.colleges">
<i><img ng-src="/static/icons/{{college}}.png" /></i>
</span>{% endverbatim %}
<span class="pull-right btn btn-success" ng-click="addDegree(degree)">Add</span>
</li>
</div>
</div>
我在哪里犯这个错误?当我点击刷新按钮时页面会刷新,但是当我调用该功能时它不会发生。
答案 0 :(得分:0)
我遇到了类似的问题而且我找不到任何解决方案,所以我使用了另一种方法,即使用$ location重定向到同一页面。当然,我想知道一个真正的解决方案,但这就是我使用临时黑客的方式 -
$window.location.href='http://yoursite.com'
会继续寻找更好的东西。不要忘记将$ location注入控制器。
答案 1 :(得分:0)
试试这个
$state.transitionTo($state.current, $stateParams, { reload: true, inherit: true, notify: true });
或者
$state.go($state.$current, null, { reload: true });