MetaDriver,
сделал вот так
var servicesCatalog = angular.module('servicesCatalog', [
'catalogControllers'
]);
servicesCatalog.run(function($rootScope, $http) {
$rootScope.ajax = false;
});
servicesCatalog.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/catalog/:categoryId', {
templateUrl: 'views/catalog.html',
controller: 'Catalog'
}).
when('/favorites', {
templateUrl: 'views/favorites.html',
controller: 'Favorites'
}).
when('/applications', {
templateUrl: 'views/applications.html',
controller: 'Applications'
}).
when('/catalog/:categoryId/:serviceId', {
templateUrl: 'views/service-detail.html'
}).
otherwise({
redirectTo: '/catalog/:categoryId'
});
}]);
catalogControllers.controller('Catalog', ['$scope', '$http', '$location', '$routeParams', '$rootScope',
function($scope, $http, $location, $routeParams, $rootScope) {
/*if($routeParams.categoryId.length == 0)
{
$routeParams.categoryId = 0;
}*/
if($rootScope.ajax == false)
{
$http(
{
method: 'POST',
url: 'ajax/ajax.php',
async: false,
data: {action: 'showCategories'}
}).
success(function(data, status, headers, config) {
$rootScope.categories = data;
$rootScope.ajax = true;
}).
error(function(error, status, headers, config) {
console.log('ERROR => ' + error);
});
}
$scope.selectedCategory = $rootScope.categories[$routeParams.categoryId];
/*setTimeout(function(){
$scope.selectedCategory = $rootScope.categories[$routeParams.categoryId];
}, 1000);*/
$scope.showServices = function (categoryId) {
$scope.selectedCategory = $rootScope.categories[categoryId];
};
Но scope.selectedCategory = $rootScope.categories[$routeParams.categoryId]; происходит раньше чем обрабатывается запрос , как это исправить?