0

I have a route with parameter like this

 var app = angular.module("myapp", ["ngRoute"]);

    app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
            $locationProvider.hashPrefix("!").html5Mode(true);

            $routeProvider

            .when('/sukien', { templateUrl: '/app/views/sukien/index.html' , controller: 'eventCtrl' })
            .when('/sukien/:id', { templateUrl: function (params) { return '/app/views/sukien/index.html?id=' + params.id }, controller: 'eventCtrl' })


        }])

why /sukien works and /sukien/:id doesn't ? indeed, angularjs seems not to understand what it is. "Uncaught TypeError: undefined is not a function"

/sukien/333 => failed to work.

1
  • Just print params to console from your function to see what it contains. Commented Nov 3, 2014 at 9:27

1 Answer 1

1

You are mixing template url, state of your application and search parameters it seems.

The templateUrl tells angularjs where to look for the html file : it will very unlikely depend on the params.id and be set via a function, but will rather be a constant.

It has nothing to see with the url that the user sees in their browser.

For example : '/app/views/sukien/suiken.html'

The url the user sees will be something like :

.../suiken/1223445

And you can then access the id in your controller via $routeParams.id

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

Comments

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.