angular/angular.io

best practice to use 3rd party lib like lodash or momentjs

payalcsureja opened this issue · 2 comments

With angular 1, we used to include 3rd party like moment/lodash/toastr lib via wrapper with service or constant.

Ex.

(function() {
  'use strict';

  angular
    .module('core.lodash')
    .factory('_', lodash);

  lodash.$inject = ['$window'];

  /* @ngInject */
  function lodash($window) {

   
    var _ = $window._;

     
    return( _ );

  }

})();

(function() {
  'use strict';

  angular
    .module('core.toastr', []);

  /*global toastr:false */
  angular
    .module('core.toastr')
    .constant('toastr', toastr)
    .config(toastrConfig);

  toastrConfig.$inject = ['toastr'];
  /* @ngInject */
  function toastrConfig(toastr) {
    toastr.options.timeOut = 4000;
    toastr.options.positionClass = 'toast-top-center';
     
  }

})();

Can someone please guide me, how to do that with angular 2/4?

Questions are better for stackoverflow.

Sure, here is the link for same http://stackoverflow.com/questions/43636523/angular-2-4-best-way-to-use-3rd-party-lib-via-wrapper

If it can be part of angular best practices, would be great. Thanks.