2015-08-28 47 views
0

如何從鏈接功能訪問與指令相關的控制器實例?如何從鏈接功能訪問與指令相關的控制器實例?

return { 
      template: template, 
      controller: controller, 
      controllerAs: 'myCtrl', // How do I access the controller instance from the link function? 
      restrict: 'E', 
      replace: true, 
      link: function(scope, element, attrs) {} 
}; 
+0

爲什麼要這麼做? – Subash

+0

我想通過傳遞''ctrls''作爲第四個參數來鏈接函數。 –

回答

1

指令中的鏈接函數接受第4個參數。您可以執行以下操作:

  return { 
      template: template, 
      controller: controller, 
      controllerAs: 'myCtrl', 
      restrict: 'E', 
      replace: true, 
      link: function(scope, element, attrs, controller) {} 
     }; 
相關問題