MCPcopy Create free account
hub / github.com/apache/cloudstack / $CompileProvider

Function $CompileProvider

tools/ngui/static/js/lib/angular.js:3684–4663  ·  view source on GitHub ↗
($provide)

Source from the content-addressed store, hash-verified

3682 */
3683$CompileProvider.$inject = ['$provide'];
3684function $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 };

Callers

nothing calls this directly

Calls 13

isStringFunction · 0.85
assertArgFunction · 0.85
forEachFunction · 0.85
isFunctionFunction · 0.85
valueFnFunction · 0.85
reverseParamsFunction · 0.85
isDefinedFunction · 0.85
getBooleanAttrNameFunction · 0.85
snake_caseFunction · 0.85
setAttributeMethod · 0.80
replaceMethod · 0.80
invokeMethod · 0.45

Tested by

no test coverage detected