0

I am using the state provider for mapping the urls , and the following is my AngularJS code.

 .state('uimenucategories', {
        url: "/MenuCategory.html",
        templateUrl: "/AppMenuMaker/MenuCategory",
        data: {pageTitle: 'Menu Category'},
        controller: "MenuCategoryController",
        resolve: {
            deps: ['$ocLazyLoad', function($ocLazyLoad) {
                return $ocLazyLoad.load([{
                    name: 'MetronicApp',
                    files: [
                           'js/controllers/MenuCategoryController.js',


                    ]
                }]);
            }] 
        }
    })

I want to take parameters from the URL to pass them to the action before rendering the view

    public ActionResult MenuCategory(int? CategoryID){}

any help for how I can send them from URL like this Dashboard/Index#/ViewMenuCategories.html?ID=1 ?

5
  • I am in iphone i will try to help you: templateUrl: function(stateParams){ return '/AppMenuMaker/MenuCategory?categoryId=' + stateParams.id; }. I dont remember exact name is service is stateParams. Commented Nov 6, 2016 at 13:32
  • @fabiosilvalima I am getting this error 'Unknown provider: $stateParams' Commented Nov 6, 2016 at 15:30
  • like i said if stateParams is right name. I will chek thia today at night Commented Nov 6, 2016 at 15:48
  • @fabiosilvalima thanks Commented Nov 6, 2016 at 20:34
  • It worked with me like that , with no need to inject a service , thanks a lot! Commented Nov 13, 2016 at 12:08

1 Answer 1

0

If you hit url 'Dashboard/Index#/ViewMenuCategories.html?ID=1' on browser, angular will search for a template on '/AppMenuMaker/MenuCategory?CategoryID=1'.

I think the code would be:

.state('uimenucategories', {
    url: "/MenuCategory.html",
    templateUrl: ['$location', function($location){
        return '/AppMenuMaker/MenuCategory?CategoryID=' + $location.search().ID || '';
        }
    }],
    data: {pageTitle: 'Menu Category'},
    controller: "MenuCategoryController",
    resolve: {
        deps: ['$ocLazyLoad', function($ocLazyLoad) {
            return $ocLazyLoad.load([{
                name: 'MetronicApp',
                files: [
                       'js/controllers/MenuCategoryController.js',


                ]
            }]);
        }] 
    }
})

Controller / Action:

public ActionResult MenuCategory(int? CategoryID)
{
    return View('');
}

You will need to reference Angular Route in your app to use $location service.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks alot !! but I get error 'Unknown provider: $location'
Did you referenced the angular route .js file? could share the file name?
I have those services injected : MetronicApp.config(['$stateProvider', '$urlRouterProvider', '$location', function ($stateProvider, $urlRouterProvider,$location) { // Redirect any unmatched url
@Hana download angular route library and put together other angular libraries angular-route.js
@Hana inject the $location inside templateUrl function and not in .config() function. Your config function must ge that: MetronicApp.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {}
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.