omer727
omer727

Reputation: 7565

Implementing a directive which includes another html

I want to use the following directive. <tabContent action="XYZ.html"> that will display me XYZ.html if the context.view is equal XYZ. So I've created the following directive:

.directive('tabContent',function(){
    return {
        restrict: 'E',
        template:'<div ng-if="view==\'{{action}}\'" ng-include="\'{{action}}.html\'"></div>',
        link: function(scope, elem, attrs) {
            scope.action = attrs.action;
        }
    }
})

is that the correct approach?
Thanks,
        Omer

Upvotes: 0

Views: 20

Answers (1)

michelem
michelem

Reputation: 14590

First of all if the directive name is tabContent so the html tag becomes: <tab-content>

Then I think there are some problems with your code, what's view? Then it should something like this:

HTML:

<tab-content action="XYZ.html"></tab-content>

JS:

.directive('tabContent',function(){
    return {
        restrict: 'E',
        template:'<div ng-include="action"></div>',
        link: function(scope, elem, attrs) {
            scope.action = attrs.action;
        }
    }
})

I removed the ng-if because I don't know what view is.

Upvotes: 1

Related Questions