Skip to content

Instantly share code, notes, and snippets.

@carloscasalar
Last active February 14, 2017 12:33
Show Gist options
  • Save carloscasalar/4f8019e9b3bf3d1461d7 to your computer and use it in GitHub Desktop.
Save carloscasalar/4f8019e9b3bf3d1461d7 to your computer and use it in GitHub Desktop.
Angular tips and links

Angular tips

AngularJS Cheat Sheets: Core Services, Directive Definition Object, and ui-router

Best Practices

Directives

Directives usage

Config an run

Filters

<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Example of delayed filter initialization using promise in angular" />
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"></script>
  <meta charset="utf-8">
  <title>Delayed Filter</title>
</head>
<body ng-app="filterExample">
  <h2>Promise in Angular Filter</h2>
  <p>{{ 'a string' | aFilter }}</p>
  <p>The above filter changes after 1 second using $timeout service.</p>
  <p>Part of the blog post at <a href="http://bahmutov.calepin.co/">http://bahmutov.calepin.co/</a></p>
</body>
</html>
angular.module('filterExample', [])
      .filter('aFilter', function registerAFilter($timeout) {
          var filterFn = function initialFilter(str) {
            return str + ' filtered initially';
          };

          $timeout(function () {
            filterFn = function newFilter(str) {
              return str + ' filtered with delayed!!!';
            };
          }, 1000);

          function tempFilter(str) {
            return filterFn(str);
          };
          tempFilter.$stateful = true;
          return tempFilter;
        });

Angular core services, directives, etc

Routing

Call a REST API

Pagination

Forms

Libs

Unit test

e2e test

Debug

Code Documentation

Building tools (Gulp, Grunt)

Performance

IDEs for Angular development

Angular IDE plugins

Angular themes, seeds and generators

Sample apps

Guides and training courses

Angular 2.0

Angular Gurus

Issues

describe('how to test with promises', function () {
  var deferred, $rootScope;

  beforeEach(function () {
    inject(function ($q, _$rootScope_) {
      $rootScope = _$rootScope_;
      deferred = $q.defer();
    });
  });
  
 it('does a thing one way', function() {
     var value;
     deferred.promise.then(function(_value_) {
         value = _value_;
     });
     deferred.resolve(10);
     expect(value).not. toBe(10); // not yet 10 because $digest hasn't run
     $scope.$digest();
     expect(value).toBe(10); // 10 because $digest already ran
 });
});

Angular 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment