Javascript 通过angular js在index.html页面中导航到另一个页面
我正在尝试从index.html页面导航到customer.html页面。我想通过angular js实现这一点,因为我正在使用angular框架。目前我通过html链接导航,但我必须通过angular来完成。因此,我希望在customer.html页面中使用的函数无法正常工作。 这是我的代码: HTML代码:index.HTML:Javascript 通过angular js在index.html页面中导航到另一个页面,javascript,java,html,sql,angularjs,Javascript,Java,Html,Sql,Angularjs,我正在尝试从index.html页面导航到customer.html页面。我想通过angular js实现这一点,因为我正在使用angular框架。目前我通过html链接导航,但我必须通过angular来完成。因此,我希望在customer.html页面中使用的函数无法正常工作。 这是我的代码: HTML代码:index.HTML: <body data-ng-controller="FirstCtrl as fctrl"> <nav clas
<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>
这是我的主ctrl.js(用于客户页面):
角度.module('restaurantApp').controller('FirstCtrl',FirstController.).controller('MainCtrl',MainController)
这是我的CustomerController:
@路径(“/first/customer”)
公共类客户控制器{
@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;
}
}
@GET
@路径(“/all”)
//以数据交换格式生成结果
//从json数据生成对象
@产生(MediaType.APPLICATION_JSON)
公众咨询响应getAll(){
AppResponse resp=新AppResponse();
//为成功/不成功的连接生成公共消息
试一试{
//如果成功,显示列表
CustomerDAO CustomerDAO=新CustomerDAO();
List customerList=customerDAO.getAll();
分别设置有效载荷(客户列表);
}捕获(外观e){
//TODO自动生成的捕捉块
e、 printStackTrace();
响应设置状态(响应错误);
分别是setMessage(如getMessage());
}
//customerDAO.getAll();
返回响应;
}
}
有点难以回答,因为有很多方法可以做到这一点,但仔细研究一下使用AngularJS进行重定向是什么意思?您正在搜索ng view
SPA之类的东西吗?是的。确切地我想使用angularjs重定向。我在索引页面中使用了“customer.html”链接。但当我试图实现customer页面中的功能时,使用了它之后,这些功能就不起作用了。
//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;
}
}
@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;
}
}