-1

I am stucked with one problemm. I have one template URL but alot of variant of state. I have one parent state and other states is the childs. now it seens like this:

 angular
    .module("StN")
    .config(config);

function config($stateProvider) {
    $stateProvider
        .state("invoice", {
            url: "/invoice",
            templateUrl: "/Scripts/js/stn/invoice/invoice.html",
            controller: "invoiceController as vm"
        })
        .state("invoice.custom", {
            url: "/castom"
        })
        .state("invoice.search", {
            url: "/search?Status?Invoice?"
        });
}

And in the controller I have switch case construction, where I check current state name and do some difference logic

angular
   .module("StN")
   .controller("invoiceController", invoiceController);

function invoiceController($http, $state) {
    switch (state.name) {
    case "invoice.search":
        //first logic 
        break;
    case "invoice.custom":
        //second logic
        break;
    case "invoice.status":
        //third logic
        break;
    }
}

I need to have different controller for each state, but this controllers must have logic of parent controller (invoiceController). How can I do that?

Example

.state("invoice", {
        url: "/invoice",
        templateUrl: "/Scripts/js/stn/invoice/invoice.html",
        controller: "invoiceController as vm"
    })
    .state("invoice.custom", {
        url: "/castom"
        controller: "DerivedinvoiceController as vm" //but it must have logic of base controller
        })
simply good
  • 991
  • 1
  • 12
  • 26
  • May Be You Can Inherit The ParentController Logic http://stackoverflow.com/questions/18461263/can-an-angularjs-controller-inherit-from-another-controller-in-the-same-module – Shankar Shastri Oct 04 '16 at 13:42
  • i think it can be, but my boss told, that it is not the best variant (he told that it is need for tests) – simply good Oct 04 '16 at 14:14

1 Answers1

0

The best you can do. Separate this logic to a Factory and use this factory in your parent controller and in it's children.