I needed to make a dynamic controller, but when I use the directive data-ng-dynamic-controller
my ng-include does not work does anyone know what it 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 my masterpageController
, and both methods exist and the return is correct, but when I use ng-dynamic-controller
the getHtmlFile()
method is not called. If I remove the ng-dynamic-controller
it normally works getHtmlFile()