How to make reusable AngularJs components

It seems like it should be easy, but I can't find the documentation on it. I am wondering how to make an Angular component (say, a filter) reusable in different applications. I created a simple filter that formats a phone number, and I would like to use it in any application. Currently, it is declared as follows:

var myModule = angular.module('myModule', ['ngSanitize']);

myModule.filter('formatFilter', function() {
  return function(input) {
    return input.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
  }
});

The question is how to make this filter multiple. Right now it is just tied to "myModule", but how can I extract it from this file to use it again elsewhere?

+5
source share
2 answers

, . , , :

angular.module('myApp',['myModule'])

, , - , - phoneFormatter sth.

+7

:

, , :

:

angular.module("lov-filter", []).filter('StartOnPage', function () {
    return function (input, start) {
        start = +start;
        return input.slice(start);
    }
});

:

var demoApp = angular.module('demoApp', ['lov-filter'])     .config(function() {

});

angular: https://github.com/rolandocc/lov-angular-directive

+2

All Articles