directive(name, directiveFactory);
Register a new directive with the compiler.
Param | Type | Details |
---|---|---|
name | stringObject |
Name of the directive in camel-case (i.e. |
directiveFactory | function()Array |
An injectable directive factory function. See the directive guide and the compile API for more info. |
ng.$compileProvider | Self for chaining. |
component(name, options);
Register a component definition with the compiler. This is a shorthand for registering a special
type of directive, which represents a self-contained UI component in your application. Such components
are always isolated (i.e. scope: {}
) and are always restricted to elements (i.e. restrict: 'E'
).
Component definitions are very simple and do not require as much configuration as defining general directives. Component definitions usually consist only of a template and a controller backing it.
In order to make the definition easier, components enforce best practices like use of controllerAs
,
bindToController
. They always have isolate scope and are restricted to elements.
Here are a few examples of how you would usually define components:
var myMod = angular.module(...);
myMod.component('myComp', {
template: '<div>My name is {{$ctrl.name}}</div>',
controller: function() {
this.name = 'shahar';
}
});
myMod.component('myComp', {
template: '<div>My name is {{$ctrl.name}}</div>',
bindings: {name: '@'}
});
myMod.component('myComp', {
templateUrl: 'views/my-comp.html',
controller: 'MyCtrl as ctrl',
bindings: {name: '@'}
});
For more examples, and an in-depth guide, see the component guide.
See also $compileProvider.directive().
Param | Type | Details |
---|---|---|
name | string |
Name of the component in camelCase (i.e. |
options | Object |
Component definition object (a simplified directive definition object), with the following properties (all optional):
|
ng.$compileProvider | the compile provider itself, for chaining of function calls. |
aHrefSanitizationWhitelist([regexp]);
Retrieves or overrides the default regular expression that is used for whitelisting of safe urls during a[href] sanitization.
The sanitization is a security measure aimed at preventing XSS attacks via html links.
Any url about to be assigned to a[href] via data-binding is first normalized and turned into
an absolute url. Afterwards, the url is matched against the aHrefSanitizationWhitelist
regular expression. If a match is found, the original url is written into the dom. Otherwise,
the absolute url is prefixed with 'unsafe:'
string and only then is it written into the DOM.
Param | Type | Details |
---|---|---|
regexp
(optional)
|
RegExp |
New regexp to whitelist urls with. |
RegExpng.$compileProvider | Current RegExp if called without value or self for chaining otherwise. |
imgSrcSanitizationWhitelist([regexp]);
Retrieves or overrides the default regular expression that is used for whitelisting of safe urls during img[src] sanitization.
The sanitization is a security measure aimed at prevent XSS attacks via html links.
Any url about to be assigned to img[src] via data-binding is first normalized and turned into
an absolute url. Afterwards, the url is matched against the imgSrcSanitizationWhitelist
regular expression. If a match is found, the original url is written into the dom. Otherwise,
the absolute url is prefixed with 'unsafe:'
string and only then is it written into the DOM.
Param | Type | Details |
---|---|---|
regexp
(optional)
|
RegExp |
New regexp to whitelist urls with. |
RegExpng.$compileProvider | Current RegExp if called without value or self for chaining otherwise. |
debugInfoEnabled([enabled]);
Call this method to enable/disable various debug runtime information in the compiler such as adding binding information and a reference to the current scope on to DOM elements. If enabled, the compiler will add the following to DOM elements that have been bound to the scope
ng-binding
CSS class$binding
data property containing an array of the binding expressionsYou may want to disable this in production for a significant performance boost. See Disabling Debug Data for more.
The default value is true.
Param | Type | Details |
---|---|---|
enabled
(optional)
|
boolean |
update the debugInfoEnabled state if provided, otherwise just return the current debugInfoEnabled state |
* | current value if used as getter or itself (chaining) if used as setter |