Skip to content

Instantly share code, notes, and snippets.

@mattkatz
Last active December 15, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattkatz/5217960 to your computer and use it in GitHub Desktop.
Save mattkatz/5217960 to your computer and use it in GitHub Desktop.
Why does this angular route never work? Nothing gets logged by TestCtrl...
/*
url is http://localhost/~matt/wp/wp-admin/admin.php?page=wordprss.php#/feed/2
*/
function FeedListCtrl($scope, $http, $routeParams,$location,$log){
$log.log('in feedscontrol');
$log.log('location is '+ $location.path());
$log.log($routeParams);
}
function TestCtrl($scope, $http,$routeParams,$log) {
$log.log('in test ctrl');
}
function EntriesCtrl($scope, $http,$routeParams, $log){
$scope.log = $log;
$log.log('in entriescontrol');
$http.get(get_url.ajaxurl+'?action=wprss_get_entries&feed_id='+$routeParams.feedId)
.success(function(data){
$scope.entries = data;
});
};
angular.module('main-content', []).
config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/feed/:id',{controller: EntriesCtrl, templateUrl: 'entries-list.html'}).
when('/feed/:id',{controller: EntriesCtrl, template:' <div id="wprss-content" ng-controller="EntriesCtrl" > <ul class="entries"> <li class="entry" ng-repeat="entry in entries" > <h2>{{entry.title}}</h2> <div class="entry-content"> {{entry.content}} </div> </li> </ul> </div> '}).
when('?page=wordprss.php#/feed/2',{controller: EntriesCtrl, template:' <div id="wprss-content" ng-controller="EntriesCtrl" > <ul class="entries"> <li class="entry" ng-repeat="entry in entries" > <h2>{{entry.title}}</h2> <div class="entry-content"> {{entry.content}} </div> </li> </ul> </div> '}).
otherwise({controller:TestCtrl });
}]);
/*
output is:
in feedscontrol
location is /feed/2
Object {}
*/
/* never gets to TestCtrl!*/
/* changed my router*/
angular.module('main-content', []).
config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider){
console.log("in router");
console.log("locationProvider.hashprefix is " + $locationProvider.hashPrefix());
$routeProvider.
otherwise({controller:TestCtrl });
}]);
/* output is:
in router app.js:3
locationProvider.hashprefix is app.js:4
Error: Unknown provider: $locationProviderProvider <- $locationProvider
at Error (<anonymous>)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment