0

I'm working with an app on Angular 1 and Ui-router, and I am trying to make so that data in urls will be preserved between states. I have read about the queryParamsHandling:'preserve' feature on Angular 2.0. However I am currently stuck with Angular 1 and I need to resolve how to keep the url data the same between states.

One option I was considering was to preserve the url:params data between states was with the ui-sref, however so far unsuccessful.

Does anyone have good tips how to resolve this?

Thanks

Aleksey Solovey
  • 4,153
  • 3
  • 15
  • 34
Mikko Lasso
  • 111
  • 1
  • 1
  • 3
  • 1
    since you tagged it with `angularjs`, don't assume people will know how `angular` works. It's best to explain what do you want your URL to look like, instead of comparing it to `queryParamsHandling` function. I suggest you look into `$stateParams` or `$transition$.params()` for handling url parameters – Aleksey Solovey May 08 '18 at 10:10
  • https://stackoverflow.com/questions/25647454/how-to-pass-parameters-using-ui-sref-in-ui-router-to-controller this is proper solution. – Devraj verma May 08 '18 at 10:11
  • Check this link https://stackoverflow.com/questions/25647454/how-to-pass-parameters-using-ui-sref-in-ui-router-to-controller – Zumm May 08 '18 at 13:53

1 Answers1

0

Router File --> route.js:

angular
    .module('moduleName')
    .config(['$stateProvider', stateProvider])

function stateProvider($stateProvider) {
    $stateProvider
    .state('lessonDetails', {
            url: '/:lessonId/details',
            views: {
                'content': {
                    templateUrl: 'lesson/lesson-details.html',
                    controller: 'lessonController'
                }
            }
     });
}

HTML file --> lesson-details.html:

<a ui-sref="lessonDetails({'lessonId': 123})">Go to details</a>

Controller -- > lesson-details.js

angular
    .module('moduleName')

    .controller('lessonController', ['$scope', '$stateParams', lessonController]);

     function lessonController($scope, $stateParams){
        //use lessonId passed as params using $stateParams
        console.log($stateParams.lessonId)
     }
DeepaliK
  • 86
  • 5