.
var cartangularPublicShoppingApp = angular.module('cartangularPublicShoppingApp', [
'ngRoute',
'CategoriesController',
'CategoryServices',
'CategoryNavigationServices',
'MenuModule'
]);
cartangularPublicShoppingApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/categories/:categoryId', {
templateUrl: 'partials/public/categories.html',
controller: 'CategoriesController'
})
}]
);
(categories.html), . , "treeFamily", .
var categoriesControllers = angular.module('CategoriesController', []);
categoriesControllers.controller('CategoriesController', ['$scope', '$routeParams' , '$location', 'CategoryService',
function($scope, $routeParams, $location, CategoryService) {
$scope.treeFamily = {
name : "Clothes",
categoryId : "4",
children: [{
name : "Clothes",
categoryId : "3",
children: [{
name : "Men Clothes",
categoryId : "2",
children: []
},{
name : "Jackets",
categoryId : "1",
children: [
{
name : "Light Jackets",
categoryId : "4",
children: [{
name : "Natural Material",
children: []
}
]
},{
name : "Heavy Jackets",
categoryId : "3",
children: []
}]
}, {
name: "Pants",
categoryId : "4",
children: []
}]
}]
}
, .
angular.module('MenuModule', [])
.directive("tree", function(RecursionHelper) {
return {
restrict: "E",
scope: {
family: '=',
'product': '&products'
},
templateUrl: './partials/public/family.html',
compile: function(element) {
return RecursionHelper.compile(element);
}
};
})
, , - .
, .
var categoryNavigationServices = angular.module('CategoryNavigationServices', []);
categoryNavigationServices.factory('RecursionHelper', ['$compile', function($compile){
var RecursionHelper = {
compile: function(element){
var contents = element.contents().remove();
var compiledContents;
return function(scope, element){
if(!compiledContents){
compiledContents = $compile(contents);
}
compiledContents(scope, function(clone){
element.append(clone);
});
};
}
};
return RecursionHelper;
}]);
html- . , .
<a href="javascript:void(0);" name="categoryId" ng-click="product(family.categoryId)">{{ family.name }}</a>
<ul>
<li ng-repeat="child in family.children">
<tree family="child" products="products(child.categoryId)"></tree>
</li>
</ul>
.html, .
<ul>
<li ng-repeat="object in treeFamily.children">
<a href="javascript:void(0);" name="categoryId" ng-click="products(object.categoryId)">{{object.name}}</a>
<ul>
<li ng-repeat="child in object.children">
<tree family="child" products="products(child.categoryId)"></tree>
</li>
</ul>
</li>
</ul>
, , , , ng-click, html, .
, .
, .
, .
:
<tree family="child" products="products(child.categoryId)">
..:
scope: {
family: '=',
'product': '&products'
},
a href html :
<a href="javascript:void(0);" name="categoryId" ng-click="product(family.categoryId)">{{ family.name }}</a>
, "", , , .