我知道,你可以通過綁定一個指令:替代方式綁定指令
HTML:
<mydirective />
JS:
app.directive('mydirective', function() {})
但是我看到this SO回答。 那麼是否有可能綁定一個像?
HTML:
<input ng-something="foo()">
JS:
app.directive('ngSomething', function() {})
或者我應該始終有template:
指令內,以便我注入的代碼。我的目的是綁定ng-keydown
上的現有輸入:
這不起作用:
<input type="text", placeholder="Search stuff" ng-model="searchBar" ng-keydown="dosomthg()">
所以我基於上述答案嘗試:
<input type="text", placeholder="Search stuff" ng-model="searchBar" ngSearchbar="dosomthg()">
[看這裏](http://plnkr.co/edit/B2D0PFiPKmxnFzFBBCrZ)...它的工作原理! –