Skip to content

Tag Archives: AngularJS

Jasmine unit tests throwing "Possibly unhandled rejection" with Angular 1.6?


Each $q.reject() throws an error if not being chained properly. First check that all calls have a .catch(). Second, if possible, isolate your error cases to an independent describe block. Example below using bardjs, but the idea should be clear enough. let stuffDataservice; const stuff = [{}]; beforeEach(function() { [...] stuffDataservice = { getStuff: function […]

Disable autocomplete automatically for all forms in AngularJS


When developing CRMs autocomplete is often useless or altogether detrimental. If you end up having a case where no element will ever need autocomplete, one of the fastest ways to achieve this is hooking an AngularJS directive to the form element: (function() { 'use strict'; angular .module('app.core') .directive('form', htmlFormDirective); function htmlFormDirective() { return { restrict: […]

AngularJS ng-repeat limitTo with Objects


<div ng-repeat="(key, value) in object | limitTo: 2"> will not work, as ngRepeat needs a string or an array to work with. A workaround is to use ng-if="$index < 2". <div ng-repeat="(key, value) in object" ng-if="$index < 2"> Do note that the order of keys for any given object may vary.

Google Analytics and Angular UI Router


Tracker service: (function () { 'use strict'; angular .module('app.core') .service('googleAnalyticsTracker', googleAnalyticsTracker); googleAnalyticsTracker.$inject = ['$state', '$window']; function googleAnalyticsTracker($state, $window) { /* jshint validthis: true */ this.trackState = trackState; //////////////// function trackState() { var stateName = $; var path = stateName.replace(/\./g, '/'); // replaces dots to mimic regular path with slashes $'set', 'page', path); $'send', 'pageview'); } […]