我正在尝试从index.html页面导航到customer.html页面。我想通过角度js这样做,因为我使用角度框架。目前我正在通过html链接导航,但我必须通过角度来做到这一点。我想在customer.html页面中使用的功能因此而无效。 这是我的代码: HTML代码:index.html:
<body data-ng-controller="FirstCtrl as fctrl">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Nishinda's Diner</a>
</div>
<div>
<ul class="nav navbar-nav">
<!--<li><a href="#">Home</a></li>-->
<li><a href="/api/first/customer">Customer</a></li>
<li><a href="ownerLogIn.html">Owner</a></li>
</ul>
</div>
</div>
</nav>
<body data-ng-controller="MainCtrl as mctrl">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div>
<ul class="nav navbar-nav">
<li> <a href="index.html">Nishinda's Diner</a></li>
<li><a href="customer.html">Guest</a></li>
<li><a href="ownerLogIn.html">Owner</a></li>
</ul>
</div>
</div>
</nav>
<div>
这两个是角度JS中的控制器: 第一ctrl.js:
angular.module('restaurantApp').controller('FirstCtrl',FirstController);
FirstController.$inject=['$http']
function FirstController($http){
var fctrl = this;
fctrl.customer= function(){
$http({
method: 'GET',
url: 'api/first/customer',
}).success(function(url){
console.log(url);
//mctrl.newCustomer=null;
}).error(function(error){
console.log(error);
});
};
}
这是我的main-ctrl.js(针对客户页面): angular.module(&#39; restaurantApp&#39;)。控制器(&#39; FirstCtrl&#39;,FirstController).controller(&#39; MainCtrl&#39;,MainController);
//injecting annotation=$http
MainController.$inject=['$http']
function MainController($http){
var mctrl = this;
mctrl.addCustomer= function(){
$http({
method: 'POST',
url: 'api/first/customer/add',
data: mctrl.newCustomer
}).success(function(data){
console.log(data);
mctrl.newCustomer=null;
if(data.status == 'success')
{
mctrl.loggedIn= true;
}else{
mctrl.loggedIn= false;
}
}).error(function(error){
console.log(error);
});
};
}
These are my controller:
FirstController:(It will be used for index.html)
@Path("/first")
public class FirstController {
@GET
@Path("/customer")
//@Consumes(MediaType.APPLICATION_JSON)
//@Produces(MediaType.APPLICATION_JSON)
public AppResponse customerPage(@Context HttpServletRequest request){
AppResponse resp = new AppResponse();
// generating the common msg for successful/ unsuccessful connection
return resp;
}
}
这是我的CustomerController: @Path(&#34; /第一/客户&#34) 公共类CustomerController {
@GET
@Path("/all")
//produce result in data exchange format
//produce object from json data
@Produces(MediaType.APPLICATION_JSON)
public AppResponse getAll(){
AppResponse resp = new AppResponse();
// generating the common msg for successful/ unsuccessful connection
try {
//if successful show list
CustomerDAO customerDAO=new CustomerDAO();
List<Customer> customerList=customerDAO.getAll();
resp.setPayload(customerList);
} catch (AppException e) {
// TODO Auto-generated catch block
e.printStackTrace();
resp.setStatus(AppResponse.ERROR);
resp.setMessage(e.getMessage());
}
//customerDAO.getAll();
return resp;
}
}