0

I hade a page with a list of orders and search button and i want the URL change depends on the search result I used $location.search and it works but I don't know how to implement it in my app.js in page URL , I want to add it to the URL so when the user clicks on back button he gets the filtering list again

this is my controller

function openPage (key,value,key1,value1) {
       $location.search(key, value);
       var params = $location.search();
    }

this is my app.js and it didn't work

 .state('qa-dashboard.orders-list', {
        url: "/orders-list/?params",
        module: "private",
        templateUrl: "app/qa-dashboard/orders/orders-list/orders-list.html",
        controller: 'OrdersListCtrl',

my controller with the search function , i call this function first thing when user enter the page

    function searchOrdersValue(){
    console.log(QaDashboardService.searchValue);
        if ( QaDashboardService.searchValue == 'pendeing'|| QaDashboardService.searchValue == 'problem'){
            model.status =QaDashboardService.searchValue;
            model.searchOrders();
        }
        else if (QaDashboardService.searchValue !== ''){

            if (isStringNumber(QaDashboardService.searchValue)){
                console.log('enter number')
                model.filterByNumber =QaDashboardService.searchValue;
                model.searchOrders()

            }

            else {
                model.startFrom= QaDashboardService.searchValue;
                model.startTo=QaDashboardService.searchValue1;
                model.searchOrders()
             }
        }

        if (model.status !==''){
            QaDashboardService.searchValue= ($stateParams.status) ? $stateParams.status:  '';

        }
        else if (model.startFrom !== ''){
            QaDashboardService.searchValue= ($stateParams.startFrom) ? $stateParams.startFrom:  '';
            QaDashboardService.searchValue1= ($stateParams.startTo) ? $stateParams.startTo:  '';

        }
        else {
            QaDashboardService.searchValue= ($stateParams.filterByNumber) ? $stateParams.filterByNumber:  '';

        }
Renad
  • 41
  • 6

2 Answers2

0

You can use $state.go(" your state name") and pass a parameter to that page like following:

function openPage (key,value,key1,value1) {
       $location.search(key, value);
       var params = $location.search();
       $state.go('qa-dashboard.orders-list',{'params':params});
    }

And on OrdersListCtrl retrieve it using $stateParams.

Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
0

Hi you can use $stateParams service. you can get para value form that and filter your list of orders.

test link: http://localhost/qa-dashboard.orders-list?orderId=1&orderName=test

Don't add this code to app.js it should be in controller. you can get para value using this code.

$stateParams must add as dependencies in controller.

var id = $stateParams.orderId;
var name = $stateParams.orderName;

Now you can filter your order list using Params.

App.js code should be.

$stateProvider.state('qa-dashboard.orders-list', {
        url: '/orders-list/?orderId$orderName',
        views: {           
                templateUrl: 'app/qa-dashboard/orders/orders-list/orders-list.html',
                controller: 'OrdersListCtrl'        
        }
    });
Mahesh Sanjeewa
  • 217
  • 2
  • 11