Eugenia Kim Eugenia Kim - 2 months ago 12x
AngularJS Question

Angular JS route parameters with limited options

I just started using Angular and currently using 1.4.2.
I would like to know how to have only three options for the URL,

- create, update, and view.

They all use the same controller, so I don't want to have separate whens such as

.when('/create ... , .when('/update ... , .when('/view ... .

I don't want any other options to be passed beside these.
It would be great if I could get some help!
Thanks :)


you could just get the parameter from $routeParams service on your controller and do whatever logic you want to do with it. see$routeParams

route config

    .when("/yourroute/:type", {
        template: "default"
        templateUrl: "template.html",
        controller: "Controller"

controller function

function Controller($routeParams) {
    switch($routeParams.type) {
        case "create":
        case "update":
        case "view":