AngularJS : ng-repeat filter when value is greater than

Create a predicate function on the relevant scope: $scope.greaterThan = function(prop, val){ return function(item){ return item[prop] > val; } } As a first argument, it takes a property name on the object. The second argument is an integer value. Use it in your view like this: <tr ng-repeat-start=”list in Data.Items | filter: greaterThan(‘NumberOfStamps’, 0)”> Demo

Custom child directive accessing scope of parent

The city directive $parent is a transcluded scope of state directive. The transcluded scope of the state directive is inherit for $parent of state directive which is controller thus that is why $parent.MyName = India. The $parent of transcluded scope is the state directive isolated scope ( scope = {} ) that is why $parent.$parent.MyName …

Read more

AngularJS directive $destroy

The i18n example you provided would work if you only ever used it once. I don’t think you should be doing the event binding inside the compile function. You can do it inside the link function instead: angular.directive(‘i18n’, [‘$rootScope’, ‘LocaleService’, function($rootScope, LocaleService) { return { restrict: ‘EAC’, link: function(scope, element, attrs) { var cleanup; var …

Read more

AngularJS UI Bootstrap Tabs that support routing

To add routing you typically use an ng-view directive. I’m not sure it’s easy enough to modify angular UI to support what you’re looking for, but here’s a plunker showing roughly what i think you’re looking for (it’s not necessarily the best way of doing it – hopefully someone can give you a better solution …

Read more

Callback function inside directive attr defined in different attr

So what seems like the best way is using the isolated scope as suggested by ProLoser app.directive(‘mySave’, function($http) { return { scope: { callback: ‘&mySaveCallback’ } link: function(scope, element, attrs) { element.on(“click”, function() { $http.post(‘/save’, scope.$parent.data).success(returnedData) { // callback defined on my utils service here scope.callback(); // fires alert } }); } } }); For …

Read more

Check existence of attribute in AngularJs Directive

The way to do this is to check for the existence of the attributes within the link function’s attrs parameter, and assign this to variables within your directive’s isolate scope. scope:{}, link: function(scope, element, attrs){ scope.status=”status” in attrs; }, This should work without having to use an if statement within your link function.