Reputation: 1740
I am using Wordpress as a backbone in one of my many to come angular projects, I'm new to angular, spend a lot of time reading and learning.
My problem at this point is that I managed to make routing work, but for some reason the default way (without html5 mode) isn't working.
I have a list, when clicking on a link I should go to a parametrized url and I get this error
http://screencast.com/t/024t0Pl6
I have an app, services and controller files, I will post the contents here:
app.js
angular.module('AngularWP', ['controllers', 'services', 'directives'])
.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
controller: 'ListController',
templateUrl: 'templates/list.html'
})
.when('/view/:id', {
controller: 'DetailController',
templateUrl: 'templates/detail.html'
})
.otherwise({
redirectTo: '/'
});
}
]);
services.js
angular.module('services', [])
.factory('getAllPosts', ['$http',
function($http) {
return {
get: function(callback) {
$http.get('/wordpress/api/get_recent_posts/').success(function(data) {
// prepare data here
callback(data);
});
}
};
}
])
controller.js
angular.module('controllers', [])
.controller('ListController', ['$scope', 'getAllPosts',
function($scope, getAllPosts) {
getAllPosts.get(function(data) {
$scope.posts = data.posts;
});
}
])
.controller('DetailController', ['$scope', 'getAllPosts', '$routeParams',
function($scope, getAllPosts, $routeParams) {
getAllPosts.get(function(data) {
console.log(data);
for (var i = data.count - 1; i >= 0; i--) {
//data.count[i]
//console.log('post id is ' + data.posts[i].id);
//console.log('routeparam is ' + $routeParams);
if (data.posts[i].id == [$routeParams.id]) {
//console.log(data.posts[i]);
$scope.post = data.posts[i];
}
};
});
//$scope.orderProp = 'author';
}
]);
What could be the problem?
Upvotes: 0
Views: 619
Reputation: 769
I had the same issue. The issue was solved for me by switching to 1.0.7.
Upvotes: 0
Reputation: 1740
Apparently the solution to this problem was this:
<script>
document.write('<base href="' + document.location + '" />');
</script>
In the template. Angular router are relative to the current URL.
Upvotes: 1