This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from angular-ui/alias
feat(alias): Created a new ui-alias module for renaming/combining directives
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
ui-alias | ||
-------- | ||
|
||
Rename third-party directives or quickly generate simple template directives for use internally in your app! | ||
|
||
* Sick of the `ui-*` `bs-*` and other such prefixes cluttering up your beautiful html? | ||
* Always find you're calling the same set of directives together? | ||
|
||
Now you can **ALIAS** it! | ||
|
||
## Installation | ||
|
||
1. Load `alias.js` | ||
2. Add `ui.alias` as a dependency | ||
3. Create a `uiAliasConfig` constant on the `ui.alias` module | ||
|
||
## Configuration | ||
|
||
* Create a `constant` on the `ui.alias` module | ||
* Keys are your alias, while the values are either a string template or a [DirectiveDefinitionObject](http://docs.angularjs.org/guide/directive#writingdirectiveslongversion) | ||
* Aliases create new directives that generate templates | ||
* Alias directives are `replace: true` by default unless explicitly set to `false` | ||
|
||
```js | ||
angular.module('ui.alias').constant('uiAliasConfig', { | ||
'alias': '<template dir1 dir2 options="customConfigScopeVar"></template>', | ||
'alias2': { | ||
template: '<another-template></another-template>', | ||
restrict: 'AEC' | ||
} | ||
// Example: | ||
date: '<input ui-date ui-date-format="mm/dd/yyyy">' | ||
|
||
}); | ||
``` | ||
|
||
## Notes | ||
|
||
* Be careful to avoid creating an alias that fires recursively | ||
Example: `<button>` -> `<ui-button>` -> `<button>` | ||
* You cannot override existing directives. Both the original *and* your alias directives will execute. | ||
* You can create multiple an alias for different configurations of the same directives / templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
angular.module('ui.alias', []).config(['$compileProvider', 'uiAliasConfig', function($compileProvider, uiAliasConfig){ | ||
uiAliasConfig = uiAliasConfig || {}; | ||
angular.forEach(uiAliasConfig, function(config, alias){ | ||
if (angular.isString(config)) { | ||
config = { | ||
replace: true, | ||
template: config | ||
}; | ||
} | ||
$compileProvider.directive(alias, function(){ | ||
return config; | ||
}); | ||
}); | ||
}]); |