Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • J 445 posts 862 karma points
    Feb 02, 2022 @ 15:29
    J
    0

    Adding $routeProvider to my custom controller

    I have 2 HTML pages sitting under the App_Plugins folder for a custom section plugin using Umbraco 8.

    I have a create page and edit page, almost doing identical tasks but the names clarify their main roles.

    For that reason i want to use one Controller. After reading some documentation it seems i can use $routeProvider so each page could use the correct controller.

    I tried adding this to my controller but so far it doesnt work example:

    $routeProvider
        .when('/item/create', {
            templateUrl: 'umbraco/backoffice/api/app/create.html',
            controller: 'itemFormController',
            resolve: {
                item: ['$route', 'itemRepository', function ($route, itemRepository) {
                    return itemRepository.getNew();
                }],
                formType: function () { return Enums.FormType.CREATE; }
            },
        })
        .when('/item/edit/:itemId', {
            templateUrl: 'umbraco/backoffice/api/app/edit.html',
            controller: 'itemFormController',
            resolve: {
                item: ['$route', 'itemRepository', function ($route, itemRepository) {
                    return itemRepository.get($route.current.params.itemId);
                }],
                formType: function () { return Enums.FormType.EDIT; },
            },
        });
    

    I wasnt sure how to add this into my controller for it to work or compare the edit parameter to be passed in?

    Can anyone offer any guidance?

Please Sign in or register to post replies

Write your reply to:

Draft