How to make momentjs not a global variable in Angularjs, if possible

I am confused when reading the Angularjs Y240 Style Guide .

It talks about creating Angular Constant global variables for global provider libraries so that we can implement vendor libraries that are otherwise global.

I understand that you must do this:

<script src="moment.js"></script>

before loading angular.js and the controllers and directives in app.js, and the momentary object is a global variable. How do you use the following code to make it a service, and you can enter it as needed?

Please correct me if I do not see the whole picture.

// constants.js

/* global toastr:false, moment:false */
(function() {
    'use strict';

    angular
        .module('app.core')
        .constant('toastr', toastr)
        .constant('moment', moment);
})();

: "" . ? , . .

+4
2

, AngularJS:

//declare 'app.core' as a dependency
angular.module('myApp', ['app.core']);

//declare the constant in your injection list
angular.module('myApp').controller('myController', ['$scope', 'moment',
    function($scope,moment) {
        //use moment as you would normally
        var now = moment();
}]);

moment - .

:

?: , . , , ( ). , .

https://github.com/johnpapa/angular-styleguide#style-y240

0

, ,

requirejs

browserify

, lib, () {} .

0

Source: https://habr.com/ru/post/1620024/


All Articles