The below directive creates a scroll to top icon on the bottom right corner of the page. On click it will smoothly scroll you position back to top. Angular Directive: function ScrollToTop() { return { template: “<a ng-click=’click()’ class=’scroll-to-top-anchor’></a>”, replace: true, scope: true, controller: function($scope) { $scope.click = function() { var startY = currentYPosition(); var stopY […]
Tag: 4
Code for Base64 Encoding and Decoding of String – Javascript
What is Base64? Base64 is a generic term for a number of similar encoding schemes that encode binary data by treating it numerically and translating it into a base 64 representation. The Base64 term originates from a specific MIME content transfer encoding. Base64 encoding schemes are commonly used when there is a need to encode […]
How to render ng-repeat in reverse order
Many times you would like to render the array contents in reverse when using ng-repeat. You can do that with a simple single line code which uses the slice and reverse method. <tr ng-repeat=”subs in subjects.slice().reverse()”> </tr> The disadvantage to this way of printing the data is that the original array contents get reversed taking up your […]
Angular ng-repeat on object and arrays
ng-repeat is similar to a for loop in javascript which lets you loop through an array of objects or values and print the information in html. For example: Suppose we have an array of people, $scope.people = [“Max”,”Gene”,”Rose”]; To print these values in a <p> tag would have a syntax something like the one shown […]
Slugify URLs using Javascript
To generate human-readable url slugs from any ordinary string, you can uyse the following code snippet in your javascript. You can use it as a function or as an angular factory method Javascript Function: var slugify = function(text){ return text.toString().toLowerCase() .replace(/\s+/g, ‘-‘) // Replace spaces with – .replace(/[^\w\-]+/g, ”) // Remove all non-word chars .replace(/\-\-+/g, […]