0

My code...

Config function

 config.$inject = ['$routeProvider', '$locationProvider'];
function config($routeProvider, $locationProvider ) {

    $routeProvider
        .when('/', {
            controller: 'LoginController',
            templateUrl: 'pages/login.view.html',
            controllerAs: 'vm'
        })
        .when('/datepicker', {
            controller: 'DatepickerController',
            templateUrl: 'pages/datepicker.view.html',
            controllerAs: 'vm'
        })
         .when('/password', {
            controller: 'PasswordController',
            templateUrl: 'pages/password.view.html',
            controllerAs: 'vm'
        })
         .when('/datatable', {
            controller: 'DatatableController',
            **templateUrl:  "I WANT TO GET HERE"**
            controllerAs: 'vm'
        })
        .otherwise({ redirectTo: 'pages/login.view.html' });

}

Controller

(function () {

angular
    .module('app')
    .controller('DatepickerController', DatepickerController);
DatepickerController.$inject = ['$location',  'UserService', '$rootScope'];
function DatepickerController($location,  UserService, $rootScope) {

frm.submit(function(ev) {
    var eCode=123;
    var start_date = $('#start_date').val();
    var end_date = $('#end_date').val();    
    var start_date = new Date($('#start_date').val());
    var sDate = start_date.getTime();
    var end_date = new Date($('#end_date').val());
    var eDate = end_date.getTime();
    $location.path('/datatable');
    var path="pages/datatable.view.html?ecode="+eCode+"&sDate="+sDate+"&eDate="+eDate;//**I want to send this url to routeprovider**        
    ev.preventDefault();
});

}
})();

I cannot access $rootScope in config function...

I need to assign this url(in path variable) to templateUrl which is in routeProvider...

How to send that url to config function?

any idea...

1

1 Answer 1

1

in you controller create a factory and assign the url to that factory method and then in config return the router url in templateUrl function.

TemplateUrl can also be a function that returns a url. It takes one preset parameter, stateParams, which is NOT injected.

     .when('/datatable', {
        controller: 'DatatableController',
        templateUrl:  function(Mconfig){
          return Mconfig.getUrl(); //config.getUrl is service method to return the url
        }
        controllerAs: 'vm'
    })

sample factory

factory('Mconfig', function() {
    return {
        var url;
        getUrl: function() {
            return url;
        },
        setUrl: function(_url) {
            url = _url
        }
    }
})

your controller

frm.submit(function(ev) {
    var eCode=123;
    var start_date = $('#start_date').val();
    var end_date = $('#end_date').val();    
    var start_date = new Date($('#start_date').val());
    var sDate = start_date.getTime();
    var end_date = new Date($('#end_date').val());
    var eDate = end_date.getTime();
    var path="pages/datatable.view.html?ecode="+eCode+"&sDate="+sDate+"&eDate="+eDate;//**I want to send this url to routeprovider**       

Mconfig.setUrl(path); 


    $location.path('/datatable');


    ev.preventDefault();
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.