Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Global functions ?
Message
From
02/09/2016 03:44:01
 
General information
Forum:
Javascript
Category:
Other
Miscellaneous
Thread ID:
01640318
Message ID:
01640389
Views:
43
Likes (1)
>Hi everybody,
>
>I have the following two functions:
>
>
>function isEmpty(value) {
>        return angular.isUndefined(value) || value === '' || value === null || value !== value;
>    }
>
>    function sort_by(field, reverse) {
>        var key = function (x) { return x[field]; };
>        reverse = [-1, 1][+!!reverse];
>
>        return function (a, b) {
>            return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
>        }
>    }
>
>I want to be able to use them from different controllers. The question is - where exactly should I put them to be able to call from my controllers?
>
>I tried in the app.js here
>
>
>(function () {
>    'use strict';
>
>    var app = angular.module('sysMgrApp', ['ui.router', 'ngSanitize', 'ngAnimate', 'toastr', 'ngCookies',
>    'ui.bootstrap', 'ui.sortable', 'ngDragDrop', 'colorpicker.module', 'ui.ace',
>    'resourceModule', 'ngFileUpload', 'ui.bootstrap.datetimepicker', 'ngMessages', 'ui.grid', 'spinnerService']);
>
>    // here I tried to put these two functions
>
>but this didn't work - my controller was unable to find them.
>
>What is the most common practice of having a library of simple common functions?
>
>Thanks in advance.

I just put them in a separate file (common.js) and load that in a core bundle.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform