2017-02-07 13:34:26 +00:00
|
|
|
import {module} from '../module';
|
|
|
|
import {kebabToCamel} from '../lib/string';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the element controller into its scope as a
|
|
|
|
* property whose name is the directive value.
|
|
|
|
*/
|
|
|
|
export function directive() {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
link: function($scope, $element, $attrs) {
|
2017-02-08 16:28:23 +00:00
|
|
|
let id = kebabToCamel($attrs.vnId);
|
2017-05-16 10:37:48 +00:00
|
|
|
let controller = $element.controller($element[0].tagName.toLowerCase());
|
2017-02-08 16:28:23 +00:00
|
|
|
|
2017-05-16 10:37:48 +00:00
|
|
|
if (!id)
|
2017-02-08 16:28:23 +00:00
|
|
|
throw new Error(`vnId: Attribute can't be null`);
|
2017-05-16 10:37:48 +00:00
|
|
|
if (!controller)
|
2017-02-08 16:28:23 +00:00
|
|
|
throw new Error(`vnId: Can't find controller for element '${id}'`);
|
|
|
|
|
|
|
|
$scope[id] = controller;
|
2017-02-07 13:34:26 +00:00
|
|
|
}
|
|
|
|
};
|
2017-05-16 10:37:48 +00:00
|
|
|
}
|
2017-02-07 13:34:26 +00:00
|
|
|
module.directive('vnId', directive);
|