Organizational Research By

Surprising Reserch Topic

how to set a controller dynamically to a directive


how to set a controller dynamically to a directive  using -'javascript,angularjs,angularjs-directive,dynamic-programming,ecmascript-6'

I'm trying to set a controller dynamically to directive

<child-directive ctrl='BankController' ctrl-as='Bankctrl' child-url='src/accounts/finance/templates/bank/bank.tpl.html'></child-directive>




let module ='abc.core.child';


class ChildDirective{
    constructor() {
        var ctrl='';
        var ctrlAs='';
        var url=''
        this.link= function(scope, element, attrs) {
           console.log(ctrl);
           url=attrs.childUrl;
           ctrl=attrs.ctrl;
           ctrlAs=attrs.ctrlAs;
         },
         this.controller = this.ctrl;
         this.controllerAs= this.ctrlAs;
         this.templateUrl =this.url;
    }

    static directiveFactory() {
       ChildDirective.instance = new ChildDirective();
       return ChildDirective.instance;
    }

}

 angular.module(module,[])
.directive('childDirective',ChildDirective.directiveFactory);

  export default module;


How to set the controller,controllerAs and templateUrl dynamically to the above directive?
Do you have any sugessions?
    
asked Oct 6, 2015 by yogeshplv
0 votes
3 views



Related Hot Questions



Government Jobs Opening


...