My custom directive fetches a navigation block from a webservice call. I am attempting to click on a navigation link that has an "ng-click" attribute set, which should call the specified function. However, the function is not being executed.
Below is my routing configuration:
var cartangularPublicShoppingApp = angular.module('cartangularPublicShoppingApp', [
'ngRoute',
'CategoriesController',
'CategoryServices',
'CategoryNavigationServices',
'MenuModule'
]);
cartangularPublicShoppingApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/cart', {
templateUrl: 'partials/public/cart.html',
controller: 'CartCtrl'
}).
when('/categories/:categoryId', {
templateUrl: 'partials/public/categories.html',
controller: 'CategoriesController'
}).
otherwise({
redirectTo: '/categories'
});
}]
);
This is the custom directive in question:
angular.module('MenuModule', [])
.directive('myCustomer', function() {
return {
restrict: 'E',
templateUrl: './partials/public/customer.html',
controller: function($scope, $sce, CategoryNavigationService) {
var z = CategoryNavigationService.getCategoryNavigation().success(function(data){
$scope.categoryNavigation = data;
var navHTML = createCategoryNavigationBar(data);
var t = $sce.trustAsHtml(navHTML);
$scope.panes = t;
}).error(function(data){
var error = "Get confident, stupid!";
var t = $sce.trustAsHtml(error);
$scope.panes = t;
});
// Recursive function for creating category navigation bar
function createCategoryNavigationBar(categoryNavigation){
// Implementation details removed for brevity
}
}
};
});
The controller linked to the HTML fragment where the directive is inserted:
var categoriesControllers = angular.module('CategoriesController', []);
categoriesControllers.controller('CategoriesController', ['$scope', '$routeParams' , '$location', 'CategoryService',
function($scope, $routeParams, $location, CategoryService) {
// Function to get products by category ID
$scope.getProductsForCategory = function(){
var categoryId = 4; // Example category ID
getProductsByCategoryIdServiceCall(CategoryService, categoryId);
}
// Service call function
function getProductsByCategoryIdServiceCall(CategoryService, categoryId){
// Implementation details removed for brevity
}
}]);
A snippet of code from categories.html showing the usage of the custom directive:
<div class="row-fluid">
<div class="span12">
<div class="navbar">
<div class="navbar-inner">
<div class="container" style="width: auto;">
<div class="span5"></div>
<div class="span2">
<div id="currentCategoryDropBoxMenu">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br />
<my-customer></my-customer>
<br />
I have attempted different approaches but the ng-click event is still not firing as expected. Any insights would be greatly appreciated.
Thank you,
David
EDITED INFO* Hey folks, thanks for looking into this problem. It is still ongoing, but I added an extra test to my html fragment for my custom directive
<div ng-bind-html="panes"></div>
<a href="javascript:void(0);" ng-click="getProductsForCategory()">testing</a>
Before the only line was the first tag which was the div. I added the 2nd line to see if it was perhaps the binding of the html directly to the div tag in the directive, or if there was a problem with the directive's configuration elsewhere.
The second tag I added should be a standard ng-click operation. my 2nd a href tag does call the function getProductsForCategory(). So it does appear to be due to my binding of my html string to the div element for the directive.
The problem is that my navigation structure i am building can have infinite nested child elements (it's basically a suckerfish select box).
This means I will have to use recursion to map out every parent child navigation structure...in a directive...