3

.when('/FOO', {
		templateUrl: 'app/components/forums/id/forums.php'
})
<td><a ng-click="setRoute('FOO')"href="forums.php?id=<?= $f_id;?>"><?php echo $f_name;?></a></td>

Soooo.

Some background. I'm making a forum, I want to do it with AngularJS.

F_id and F_name has been declared earlier. (Not really relevant to the problem here.)

What I want to do, is dynamic routing. How can I make angular to work with the php's ?id=id mechanism? So that when I click on that forum it will open the right forum?

  • Dynamic routing, how?
1
  • You have to decide, do you want angular routing or navigation by href and page reloading, if you want to load content from php i suggest you define controller on route and params that you want to pass and then in controller use $http.get() to get content that you want Commented Feb 9, 2015 at 12:22

1 Answer 1

2

Well you want to start with a route of the following form, your template should be generic and display the values fetched for a forum whose details will be passed to the ForumController.

.when('/FOO/:id', {
        templateUrl: 'app/components/forums/forums.php',
        controller: 'ForumController',
        resolve: {
          forum: function ($routeParams) {
             // fetch your forum details here using $routeParams.id
          }
        }
})

Although for completeness I should mention that you can in fact define templateUrl as a function so that you can return a dynamic template if you really want to, but I suspected that is not what you want.

.when('/FOO/:id', {
        templateUrl: function ($routeParams) {
            return 'app/components/forums/' + $routeParams.id + '/forums.php';
        }
})
Sign up to request clarification or add additional context in comments.

1 Comment

Please see my edit above, if your PHP script already get the forumId from the url and renders the page correctly, In this case you can define templateUrl as a function which would return your template.

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.