1

i am trying to make a dynamic website/cms with angularjs.
So i also want to add a way to fetch blogs inside a persific page, normally i would do this with get requests and just get it like that. but now it seems that angular doesn't really like when you do this and so everything gets messed up. So basicly the thing i am looking for is a way to do: http://example.com/#/news/[BLOGPOST_ID] (where news is content/news.php (see code).

my current reroute:

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

app.config(['$routeProvider', function($routeProvider) {
        $routeProvider.
               when('/welkom', {templateUrl: 'content/welkom.php'}).
                    when('/lidworden', {templateUrl: 'content/lidworden.html'}).
                    when('/news', {templateUrl: 'content/news.php'}).
                    when('/signup', {templateUrl: 'content/signup.php'}).
                    when('/login', {templateUrl: 'content/login.html'}).
                otherwise({redirectTo: '/welkom'});
}]);

sorry if this has already been asked, i just don't know how to correctly put this question.

EDIT: 'https://stackoverflow.com/a/23663579/3216211 found something here that works fine out of the box, thanks anyways.' Solved.

Community
  • 1
  • 1
Matt Smeets
  • 398
  • 4
  • 15

2 Answers2

0

Option 1 :

route config

app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
        when('/welkom', {templateUrl: 'content/welkom.php'}).
        when('/lidworden', {templateUrl: 'content/lidworden.html'}).
        when('/news/:id', {templateUrl: '', 
                           controller : 'NewsController'}).
        when('/signup', {templateUrl: 'content/signup.php'}).
        when('/login', {templateUrl: 'content/login.html'}).
        otherwise({redirectTo: '/welkom'});
}]);

NewsConttroller

app.controller('NewsController', function($routeParams, $location) {

   $location.path("/content/news.php?id=" + $routeParams.id);
});

this way, you pass the param as a query string to the php page.

Option 2 :

dynamically change the template URL.follow this thread - AngularJS - How to use $routeParams in generating the templateUrl?

Community
  • 1
  • 1
Rabi
  • 2,210
  • 17
  • 18
  • how would i get the $location variable. i cant seem to find anywhere what all the args for the constructor can be. – Matt Smeets Mar 18 '15 at 17:22
  • sorry about that. check out the updated code . you can pass the $location servic like this - app.controller('NewsController', function($routeParams, $location) {...}); – Rabi Mar 18 '15 at 18:39
0

https://stackoverflow.com/a/23663579/3216211 found something here that works fine out of the box, thanks anyways.

Community
  • 1
  • 1
Matt Smeets
  • 398
  • 4
  • 15