Skip to content

Instantly share code, notes, and snippets.

@ianrodrigues
Last active May 8, 2016 19:47
Show Gist options
  • Save ianrodrigues/0ae7b3d87ffb11e90262d400266a82cc to your computer and use it in GitHub Desktop.
Save ianrodrigues/0ae7b3d87ffb11e90262d400266a82cc to your computer and use it in GitHub Desktop.
(function() {
'use strict';
angular
.module('app')
/** será <acme-hello-world></acme-hello-world> */
.directive('acmeHelloWorld', acmeHelloWorld);
/** @ngInject */
function acmeHelloWorld() {
var directive = {
restrict: 'E',
templateUrl: '/path/to/template.html',
controller: acmeHelloWorld,
controllerAs: 'vm',
link: function(scope, element) {
/** adicionei o nome da classe manualmente */
/** mas queria que ele pegasse o nome da diretiva(lá da linha 7) já normalizado */
element.addClass('acme-hello-world');
/** no final minha diretiva ficará: <acme-hello-world class="acme-hello-world"></acme-hello-world> */
}
};
return directive;
/** @ngInject */
function acmeHelloWorld() {
/** some logic here */
}
}
})();
@alissonbrunosa
Copy link

alissonbrunosa commented May 8, 2016

link: function(scope, element, attrs) {
        /** adicionei o nome da classe manualmente */
        /** mas queria que ele pegasse o nome da diretiva(lá da linha 7) já normalizado */
        element.addClass(attrs.$attr.acmeHelloWorld); // $attr é um objeto que contém o seguinte valor {nomeDaDirective: "nome-da-directive"}

        /** no final minha diretiva ficará: <acme-hello-world class="acme-hello-world"></acme-hello-world> */
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment