mercredi 25 novembre 2015

AngularJS - Is this the right way to write a directive?

I was trying to declare a directive, it is apparently right but when I load it in html nothing occurs.

This is the code:

(function() {
    'use strict';

    var app = angular
        .module('App');

    app.directive('directiveFunction', directiveFunction);

    function directiveFunction(){
        return {
            restrict: 'EA',
            replace: true,
            template: '<div>Example</div>',
            controller: directiveController,
            controllerAs: 'example',
            bindToController: true,
            link: linkFunction
        }
    }

    linkFunction.$inject = ['$scope', 'elem', 'attrs', 'ctrl'];

    function linkFunction(scope, element, attrs, ctrl) {}

    function directiveController() {
        var example = this;
    }

})();

I call this in html as <directive-function></directive-function> but it does nothing.




Aucun commentaire:

Enregistrer un commentaire