Javascript 使用angular重定向到html页面
我试图通过点击按钮将Javascript 使用angular重定向到html页面,javascript,angularjs,url,url-rewriting,Javascript,Angularjs,Url,Url Rewriting,我试图通过点击按钮将productlisting.html页面重定向到search.html,但URL栏中附加的URL为: /仪表板html/product-listing1.html#/#%2Fsearch.html%3Fquery=饼干 我希望它是这样的 /仪表板html/search.html%?查询=饼干 我的代码script.js是: Array.prototype.chunk = function (groupsize) { var sets = []; var ch
productlisting.html
页面重定向到search.html
,但URL栏中附加的URL为:
/仪表板html/product-listing1.html#/#%2Fsearch.html%3Fquery=饼干
我希望它是这样的
/仪表板html/search.html%?查询=饼干
我的代码script.js
是:
Array.prototype.chunk = function (groupsize) {
var sets = [];
var chunks = this.length / groupsize;
for (var i = 0, j = 0; i < chunks; i++, j += groupsize) {
sets[i] = this.slice(j, j + groupsize);
}
return sets;
};
var data_bind=angular.module('my_app', []);
data_bind.controller('productController', function ($scope, $http, $location)
{
var isProductListingpage = false;
$scope.init = function (isProductListpage){
isProductListingpage = isProductListpage;
// if this is not search page, get the query params from url and get the products to show from server
if(!isProductListingpage)
{
var queryParam = location.search;
var request_url='http://dmsp1-kakash.boxfuse.io:9000/products?'+queryParam;
sendRequest(request_url);
}
}
function sendRequest(request_url)
{
$http({
method : 'GET',
url : request_url,
headers : {'Content-Type' : 'application/json'}
}).success(function(response){
if(response.errors){
$scope.errorName = response.errors.name ;
$scope.errorUserName = response.errors.username;
$scope.errorEmail = response.errors.email;
}
else
{
$scope.product = response.data.products;
$scope.productGroups = $scope.product.chunk(3);
}
});
}
$scope.search_field={};
$scope.searchdata= function()
{
var queryParam = "query="+encodeURI($scope.search_field.search);
var request_url='http://dmsp1-kakash.boxfuse.io:9000/products?'+queryParam;
// If this is product listing page, we need to redirect to search page,
// otherwise make a request to server
if(isProductListingpage) {
//$window.location.href = '/index.html'
$location.url('#/search.html?'+queryParam);
}
else {
sendRequest(request_url);
}
}
$scope.search_field1={};
$scope.search_page= function(event)
{
var $target = $(event.target);
if($target.hasClass('sub-category'))
{
var subCategory = $target.clone() //clone the element
.children() //select all the children
.remove() //remove all the children
.end() //again go back to selected element
.text();
var $temp = $target.closest('.submenu');
var $mainCategoryElement = $temp.siblings('.main-category').first();
var mainCategory = $mainCategoryElement.text();
// Encode both the values
subCategory = encodeURI(subCategory);
mainCategory = encodeURI(mainCategory);
var queryParam = 'cat='+mainCategory+"&subcat="+subCategory;
var request_url='http://dmsp1-kakash.boxfuse.io:9000/products?'+queryParam;
// If this is product listing page, we need to redirect to search page,
// otherwise make a request to server
if(isProductListingpage) {
$location.url('#/search.html?'+queryParam);
}
else {
sendRequest(request_url);
}
}
}
});``
Array.prototype.chunk=函数(groupsize){
var集=[];
var chunks=this.length/groupsize;
for(变量i=0,j=0;i
您应该使用默认的角度路由器或ui路由器并定义清除状态。您尝试过使用ui路由器吗?还是默认的角度路由器?我相信你的方法是错误的。