Good time. Faced such a literacy problem. I have several states that $stateprovider can accept, and all these states have the same template (TemplateURL) and are descendants from the default state (which would be less to write).
Now it looks like this:
(function () { 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?" }); } })(); Depending on the current state, slightly different logic must be executed (in this case, different filtering), this happens at the start of the controller. At the moment it looks like this
angular .module("StN") .controller("invoiceController", invoiceController); function invoiceController($http, $state) { switch (state.name) { case "invoice.search": //ΠΠ΄Π½Π° Π»ΠΎΠ³ΠΈΠΊΠ° break; case "invoice.custom": //Π΄ΡΡΠ³Π°Ρ Π»ΠΎΠ³ΠΈΠΊΠ° break; case "invoice.status": //Π΅ΡΠ΅ 1 Π»ΠΎΠ³ΠΈΠΊΠ° break; } } Because of this, a problem arises, if I need some other functionality depending on the current state , I will have to make such a switch again.
Help please make this code more optimized. Thank.