Angular - Directives and module usage

Having studied various projects and read as much documentation as possible, I ran into the problem of including directives in my application. The application is configured as follows:

app.js - only the top

angular.module('ngDashboard', ['ngCookies','ngResource','ngDashboard.filters', 'ngDashboard.services', 'ngDashboard.directives'])

All modules work fine, except (this is an application rewritten from the example) for directives that do not work at all:

directives.js - the following does NOT work and does not execute the directive in the view:

angular.module('ngDashboard.directives', []).
  directive('funkyElement', function () {
    return {
        restrict: 'E',
        transclude: true,
        scope: 'isolate',
        template: '<div>gonna parse this: {{orig}} <br/>... and get this: {{obj}}</div>',
        //templateUrl: 'template.html',
        compile:function (element, attr, transclusionFunc) {
            return function (scope, iterStartElement, attr) {
                var origElem = transclusionFunc(scope);
                var content = origElem.text();
                scope.orig = content;
                scope.obj = my_custom_parsing(content);
            };
        }
    };
});

The following file in the same directives.js file works correctly, and the directive executes:

angular.module('ng').directive('funkyElement', function () {
    return {
        restrict: 'E',
        transclude: true,
        scope: 'isolate',
        template: '<div>gonna parse this: {{orig}} <br/>... and get this: {{obj}}</div>',
        //templateUrl: 'template.html',
        compile:function (element, attr, transclusionFunc) {
            return function (scope, iterStartElement, attr) {
                var origElem = transclusionFunc(scope);
                var content = origElem.text();
                scope.orig = content;
                scope.obj = my_custom_parsing(content);
            };
        }
    };
});

HTML is simple:

<funky-element>
    Parse me... come ooooon! Just parse meee!
</funky-element>

My question is how to properly enable the set of directives and maybe why the first example (using ngDashboard.services) does not work.

+5
source share
1 answer

, app.js, , , , ( ). ​​ , app.js, :

  • , , .
  • .
  • , ng- ( , - ).
  • , .
  • , , /.

, Angular, , ng, . , , .

+5

All Articles