Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Global functions ?
Message
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Autre
Titre:
Global functions ?
Divers
Thread ID:
01640318
Message ID:
01640318
Vues:
51
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.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform