Skip to content

Instantly share code, notes, and snippets.

@alexilyaev
Last active August 29, 2015 14:25
Show Gist options
  • Save alexilyaev/6a517cba167693cf75f0 to your computer and use it in GitHub Desktop.
Save alexilyaev/6a517cba167693cf75f0 to your computer and use it in GitHub Desktop.
Angular Guidelines when using WebPack

No more IIFE

  • WebPack wraps each requireed code with a function, so there's no need to wrap our code with an IIFE
/**
 * Good
 */

'use strict';

function TestController($scope) {

}

module.exports = TestController;

/**
 * Bad
 */
 
(function () {
	'use strict';

  function TestController($scope) {
  
  }
  
  module.exports = TestController;
}());

Dependency Injection

/**
 * Good
 */

'use strict';

function TestController($scope) {

}

module.exports = TestController;

/**
 * Bad
 */

'use strict';

function TestController($scope) {

}

module.exports = ['$scope', TestController];

/**
 * Bad
 */

'use strict';

function TestController($scope) {

}

TestController.$inject = ['$scope'];

module.exports = TestController;
  • In special cases where creating things dynamically, add a /* @ngInject */ comment right before the function that needs to be annotated (see Explicit annotations with ngInject)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment