ddidi2015-08-07 12:16:20
ddidi, 2015-08-07 12:16:20

Angular dynamically change controller by name?

How to do the same with just changing the ng-include
controller ?
only works with 1st binding, not on change

.directive('dynamicCtrl', ['$compile', '$parse', function ($compile, $parse) {
        return {
            restrict: 'A',
            terminal: true,
            priority: 100000,
            link: function (scope, elem) {
                var name = $parse(elem.attr('dynamic-ctrl'))(scope);
                elem.attr('ng-controller', name);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Sergey, 2015-08-07

change the template simply, and "dynamically replace the controller" is an awl. Override the entire directive that the controller refers to.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question