Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 1c5c5e1

Browse files
committed
Merge pull request #126 from angular-ui/alias
feat(alias): Created a new ui-alias module for renaming/combining directives
2 parents 2c98a85 + 1582d54 commit 1c5c5e1

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

modules/alias/README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
ui-alias
2+
--------
3+
4+
Rename third-party directives or quickly generate simple template directives for use internally in your app!
5+
6+
* Sick of the `ui-*` `bs-*` and other such prefixes cluttering up your beautiful html?
7+
* Always find you're calling the same set of directives together?
8+
9+
Now you can **ALIAS** it!
10+
11+
## Installation
12+
13+
1. Load `alias.js`
14+
2. Add `ui.alias` as a dependency
15+
3. Create a `uiAliasConfig` constant on the `ui.alias` module
16+
17+
## Configuration
18+
19+
* Create a `constant` on the `ui.alias` module
20+
* Keys are your alias, while the values are either a string template or a [DirectiveDefinitionObject](http://docs.angularjs.org/guide/directive#writingdirectiveslongversion)
21+
* Aliases create new directives that generate templates
22+
* Alias directives are `replace: true` by default unless explicitly set to `false`
23+
24+
```js
25+
angular.module('ui.alias').constant('uiAliasConfig', {
26+
'alias': '<template dir1 dir2 options="customConfigScopeVar"></template>',
27+
'alias2': {
28+
template: '<another-template></another-template>',
29+
restrict: 'AEC'
30+
}
31+
// Example:
32+
date: '<input ui-date ui-date-format="mm/dd/yyyy">'
33+
34+
});
35+
```
36+
37+
## Notes
38+
39+
* Be careful to avoid creating an alias that fires recursively
40+
Example: `<button>` -> `<ui-button>` -> `<button>`
41+
* You cannot override existing directives. Both the original *and* your alias directives will execute.
42+
* You can create multiple an alias for different configurations of the same directives / templates

modules/alias/alias.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
angular.module('ui.alias', []).config(['$compileProvider', 'uiAliasConfig', function($compileProvider, uiAliasConfig){
2+
uiAliasConfig = uiAliasConfig || {};
3+
angular.forEach(uiAliasConfig, function(config, alias){
4+
if (angular.isString(config)) {
5+
config = {
6+
replace: true,
7+
template: config
8+
};
9+
}
10+
$compileProvider.directive(alias, function(){
11+
return config;
12+
});
13+
});
14+
}]);

0 commit comments

Comments
 (0)