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()