angularjs - Pass custom controller to angular's directive -


i have directive looks this

<list source="userlist" avatar-url="avatarpath" search="search"></list> 

and defined was:

    .directive('list', function($rootscope) {          return {             restrict: 'e',             transclude: true,             templateurl: 'templates/list.html',             scope: {                 source:'=',                 search:'=',                 avatarurl:'='             }         }      }) 

is there way specify controller want use inside directive smth this:

    <list source="userlist" avatar-url="avatarpath" search="search" controller="listctrl"></list>     <list source="userlist" avatar-url="avatarpath" search="search" controller="adminlistctrl"></list> 

as understood, have 2 different functions call within each controller.

i that:

make div ng-controller="yourcontrollername" , use directive inside , pass function name

something like:

<div ng-controller="listctrl">     <list source="userlist" avatar-url="avatarpath" search="search" function-to-call="somefunctionnameinuserlist()"></list> </div> <div ng-controller="adminlistctrl">     <list source="userlist" avatar-url="avatarpath" search="search" function-to-call="somefunctionnameinadminlistctrl()"></list> </div> 

add functiontocall inside directive:

scope: {     source:'=',     search:'=',     avatarurl:'=',     functiontocall : '=' } 

now use functiontocall() inside directive template in ng-click or ng-submit or anywhere need

hopefully got point. works in our project fine.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -