ng-include does not work after using a directive

Asked

Viewed 278 times

0

I needed to make a dynamic controller, but when I use the directive data-ng-dynamic-controller my ng-include doesn’t work someone knows what can be?

ng-Dynamic-controller directive

appModule.directive('ngDynamicController', ['$compile', '$parse',function($compile, $parse) {
    return {
        scope: {
            name: '=ngDynamicController'
        },
        restrict: 'A',
        terminal: true,
        priority: 100000,
        link: function(scope, elem, attrs) {
            elem.attr('ng-controller', scope.name);
            elem.removeAttr('data-ng-dynamic-controller');
            elem.removeAttr('ng-dynamic-controller');

            $compile(elem)(scope);
        }
    };
}]);

HTML

<div class="page-content-wrapper" data-ng-controller="masterpageController as mpc">

    <div class="page-content" ng-dynamic-controller="mpc.getController()">
            <div class="page-head">
                <div class="page-title">
                    <h1>{{pageTitle}}
                        <small>{{pageDescription}}</small>
                    </h1>
                </div>
            </div>
            <ul class="page-breadcrumb breadcrumb">
                <li>
                    <a href="javascript:;">AppName</a>
                    <i class="fa fa-circle"></i>
                </li>
                <li>
                    <span class="active">{{pageTitle}}</span>
                </li>
            </ul>
            <!-- Não funciona... -->
            <div data-ng-include="mpc.getHtmlFile()"></div>

        </div>
</div>

Note: mpc is mine masterpageController, and both methods exist and the return is correct but when I use the ng-dynamic-controller the method getHtmlFile() nor is called. In case I remove the ng-dynamic-controller works normally the getHtmlFile()

1 answer

0

I got it sorted, apparently it’s the terminal I removed him the priority and worked normally.

appModule.directive('ngDynamicController', ['$compile', '$parse',function($compile, $parse) {
    return {
        scope: {
            name: '=ngDynamicController'
        },
        restrict: 'A',
        terminal: true,
        priority: 100000,
        link: function(scope, elem, attrs) {
            elem.attr('ng-controller', scope.name);
            elem.removeAttr('data-ng-dynamic-controller');
            elem.removeAttr('ng-dynamic-controller');

            $compile(elem)(scope);
        }
    };
}]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.