0

I am struggling with the nginx config file with angularjs route.

In my case, I have these HTMLs:

index.html description.html dashboard.html

The dashboard.html is the one with angularjs code.

Here is my current nginx config file:

upstream panda.dev {
    server 127.0.0.1:3333 max_fails=3 fail_timeout=30s;
}

server {
    listen       80;
    server_name  panda.dev;
    root /Users/Jeremy/Documents/Projects/PandaUnion/web/converted-html;

    # serve static files directly
    location / {
        index index.html$args;
        try_files $uri$args $uri$args/ $uri/ /dashboard.html$args =404;
    }
}

Here is my angular code:

PandaUnion.controller('PandaController', function($routeParams, $location) {
  console.log($routeParams);
});

var templateURL = '/partials';

PandaUnion.config(function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true);
  return $routeProvider.when('/dashboard/:user_id', {
    templateUrl: templateURL + '/home.html'
  }).when('/dashboard/:user_id/setting', {
    templateUrl: templateURL + '/setting.html'
  }).when('/dashboard/:user_id/bill', {
    templateUrl: templateURL + '/bill.html'
  });
});

With this config, I can get dashboard.html via visiting /dashboard/123, but I can't get 123 as routeParam in angular.

It should print {user_id: 123} when I visit /dashboard/123 but I only see an empty Object.

What goes wrong here? Please help...

(sorry for my poor English)

1 Answer 1

1

Have a look at the AngularJS tutorial. As you can see there, you have to bind the parameter (user_id in your case) via the $routeParams object.

So:

  1. Define a controller for the when() statements
  2. Inject the $routeParams object in that controller
  3. Bind the parameters to the $scope object
  4. In your template make sure you are within the controller boundaries when referring to "user_id"

Hope that helps.

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.