我想使用'重新加载'按钮,以便它可以用来重新加载ng-view
中的数据,而无需重新加载整个页面,因为我在$route.reload
中的custom.js
函数中使用了ng-click
,我希望使用students.html
触发在not a function
页面的按钮内。
但它没有在控制台中给出$route
的错误。
当我从控制器中删除参数$route.reload
并从我的文件custom.js
中删除angularjs
的相应功能时,我的页面工作正常。
我是index.html
的初学者。
请评论任何查询。
这是我的<!DOCTYPE html>
<html ng-app="myModule">
<head>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<div class="row body">
<div class="col-lg-4 col-md-4 col-md-4 col-xs-12">
<ul>
<li>
<a href="#!/home">Home</a>
</li>
<li>
<a href="#!/students">Students</a>
</li>
</ul>
</div>
<div class="col-lg-8 col-md-8 col-md-8 col-xs-12">
<p>Website Contents</p>
<ng-view></ng-view>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<script src="custom.js"></script>
</body>
</html>
custom.js
这是var myApp = angular.module("myModule",["ngRoute"])
.config(function($routeProvider){
$routeProvider
.when("/home",{
template : "<h3> \
Home \
</h3> \
<p> \
This is a sample text. \
</p>",
controller : "homeController",
controllerAs : "homeCtrl"
})
.when("/students",{
templateUrl : "files/students.html",
controller : "studentController",
controllerAs : "studentCtrl"
})
.otherwise({
redirectTo : "/home"
});
})
.controller("homeController",function(){
this.message = "Home";
})
.controller("studentController",function($http,$route){
var virtual_stu_ctrl = this;
virtual_stu_ctrl.reloadData1() = function(){
$route.reload();
}
virtual_stu_ctrl.message = "Students";
virtual_stu_ctrl.students = [ { "id": "1", "name": "Aditi Musunur" },
{ "id": "2", "name": "Jitendra Choudhary" },
{ "id": "8", "name": "Kanyana Saunak" }];
});
home.html
以下是<h1>
{{ homeCtrl.message }}
</h1>
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
students.html
这是<h1>
{{ studentCtrl.message }}
</h1>
<div>
<ul>
<li ng-repeat="student in studentCtrl.students">
{{ student.name }}
</li>
</ul>
<br />
<button ng-click="studentCtrl.reloadData1()">Reload Data</button>
</div>
svn commit