Angularjs two directives on one textbox -


i have 2 directives in single textbox. 1 datetimepicker , focus directive.

datetimepicker :

app.directive('datetimepicker', function() {     return {         restrict: 'a',         require : '?ngmodel',         link: function(scope, element, attrs, ngmodelctrl) {           element.datetimepicker({             format: "yyyy-mm-dd  hh:ii:ss",             autoclose: true,             todaybtn: true           }).on('setdate', function(e) {             ngmodelctrl.$setviewvalue(e.date);             scope.$apply();           });         }     }; }); 

focus :

app.directive('focus',function($timeout) {     return {         restrict: 'a',         scope : {             trigger : '@focus'         },         link : function(scope, elem,attrs) {             var focusables = $(":focusable");             scope.$watch('trigger', function(value) {                 if (value === "true") {                     $timeout(function() {                         elem[0].focus();                     });                                          }                                        });             elem.bind('keydown', function(e) {                 var code = e.keycode || e.which;                 if (code === 13) {                     var current = focusables.index(this);                     var next = focusables.eq(current + 1).length ? focusables.eq(current + 1) : focusables.eq(0);                     next.focus();                     e.preventdefault();                 }               });         }     }; }); 

this textbox

<input datetimepicker ng-model='dob' focus/> 

i getting below error

error: [$compile:multidir] multiple directives [focus, datepicker] asking new/isolated scope on: <input datepicker="" ng-model="dob" focus=""> 

how make these 2 directives work in textbox?

try not provide isolate scope manually first directive because don't need use scope:false, work so.

app.directive('datetimepicker', function() {     return {         restrict: 'a',         require : '?ngmodel',         scope: false,         link: function(scope, element, attrs, ngmodelctrl) {           element.datetimepicker({             format: "yyyy-mm-dd  hh:ii:ss",             autoclose: true,             todaybtn: true           }).on('setdate', function(e) {             ngmodelctrl.$setviewvalue(e.date);             scope.$apply();           });         }     }; }); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -