($provide)
| 3682 | */ |
| 3683 | $CompileProvider.$inject = ['$provide']; |
| 3684 | function $CompileProvider($provide) { |
| 3685 | var hasDirectives = {}, |
| 3686 | Suffix = 'Directive', |
| 3687 | COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/, |
| 3688 | CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/, |
| 3689 | MULTI_ROOT_TEMPLATE_ERROR = 'Template must have exactly one root element. was: ', |
| 3690 | urlSanitizationAllowlist = /^\s*(https?|ftp|mailto|file):/; |
| 3691 | |
| 3692 | |
| 3693 | /** |
| 3694 | * @ngdoc function |
| 3695 | * @name ng.$compileProvider#directive |
| 3696 | * @methodOf ng.$compileProvider |
| 3697 | * @function |
| 3698 | * |
| 3699 | * @description |
| 3700 | * Register a new directives with the compiler. |
| 3701 | * |
| 3702 | * @param {string} name Name of the directive in camel-case. (ie <code>ngBind</code> which will match as |
| 3703 | * <code>ng-bind</code>). |
| 3704 | * @param {function} directiveFactory An injectable directive factroy function. See {@link guide/directive} for more |
| 3705 | * info. |
| 3706 | * @returns {ng.$compileProvider} Self for chaining. |
| 3707 | */ |
| 3708 | this.directive = function registerDirective(name, directiveFactory) { |
| 3709 | if (isString(name)) { |
| 3710 | assertArg(directiveFactory, 'directive'); |
| 3711 | if (!hasDirectives.hasOwnProperty(name)) { |
| 3712 | hasDirectives[name] = []; |
| 3713 | $provide.factory(name + Suffix, ['$injector', '$exceptionHandler', |
| 3714 | function($injector, $exceptionHandler) { |
| 3715 | var directives = []; |
| 3716 | forEach(hasDirectives[name], function(directiveFactory) { |
| 3717 | try { |
| 3718 | var directive = $injector.invoke(directiveFactory); |
| 3719 | if (isFunction(directive)) { |
| 3720 | directive = { compile: valueFn(directive) }; |
| 3721 | } else if (!directive.compile && directive.link) { |
| 3722 | directive.compile = valueFn(directive.link); |
| 3723 | } |
| 3724 | directive.priority = directive.priority || 0; |
| 3725 | directive.name = directive.name || name; |
| 3726 | directive.require = directive.require || (directive.controller && directive.name); |
| 3727 | directive.restrict = directive.restrict || 'A'; |
| 3728 | directives.push(directive); |
| 3729 | } catch (e) { |
| 3730 | $exceptionHandler(e); |
| 3731 | } |
| 3732 | }); |
| 3733 | return directives; |
| 3734 | }]); |
| 3735 | } |
| 3736 | hasDirectives[name].push(directiveFactory); |
| 3737 | } else { |
| 3738 | forEach(name, reverseParams(registerDirective)); |
| 3739 | } |
| 3740 | return this; |
| 3741 | }; |
nothing calls this directly
no test coverage detected