Kadzhaev Marat
Kadzhaev Marat

Reputation: 1317

AngularJS, migrate from directive to component

I'm trying to add a component instead of a directive but it doesn't work. my directive:

    (function() {
    'use strict'; 
    angular.
        module('eventeditor')
        .directive("displayTab",
            function() {
                return({
                    templateUrl: function(elem, attr){
                        if(attr.tabname === 'details') return "/organizer/fragments/detailsform.html";
                    }
                });
            }
        );
    })();

Component style:

(function() {
'use strict';

angular.
    module('eventeditor')
    .component("displayTab", {
        templateUrl: function($element, $attrs) {
            if ($attrs.tabname === 'details') return "/organizer/fragments/detailsform.html";
        }
    });

})();

What am I doing wrong? I use my template like:

<div ng-switch="nav.getTab()">
    <div ng-switch-when="details" display-tab="" tabname="details">details</div>
</div>

Upvotes: 0

Views: 568

Answers (1)

Shuhei Kagawa
Shuhei Kagawa

Reputation: 4777

Components work only on element names while directives default to element names and attribute names.

<div ng-switch="nav.getTab()">
    <display-tab ng-switch-when="details" tabname="details">details</display-tab>
</div>

Upvotes: 1

Related Questions