How to set the dynamic controller for directives?

前端 未结 3 1037
无人共我
无人共我 2020-11-28 10:46

Talk is cheap, show my codes first:

HTML:

directive:

angular.modul         


        
3条回答
  •  春和景丽
    2020-11-28 11:05

    1- you don't need to use: var parentElem = $(elem); as elem is a jquery element. This is similar to: $($('#myid'))

    2- you can not dynamically assign a controller, because directive controller is instantiated before the prelinking phase.

    The directive controller has access to attrs, so you can dynamically choose which internal function (functions inside your controller) according to the value of your attrs['addIcons']

    ps. note attrs['addIcons'] is camel naming.

提交回复
热议问题