>> link: function (scope, element) { >> var noFocus = angular.isDefined(scope.noFocus) ? scope.noFocus : false; >> console.log('NoFocus defined=' + angular.isDefined(scope.noFocus) + ' Id= ' +scope.Id + ' noFocus=' + noFocus)>>
>element.id >// or >element.name >No, this didn't work. By looking in the debugger I found the following syntax to work
<input sm-focus ...>or
<input sm-focus="false" ...>and in the last case don't set the focus.
(function () { 'use strict'; var app = angular.module('sysMgrApp'); app.directive('smFocus', [ '$timeout', function ($timeout) { return { restrict: 'A', scope: { noFocus: "=?" }, link: function (scope, element) { var noFocus; if (angular.isDefined(scope.noFocus)) { console.log("noFocus attribute defined"); noFocus = scope.noFocus; } else { console.log("noFocus attribute is not defined") noFocus = false; } console.log('Element Id= ' + element[0].attributes["id"].value + ' noFocus=' + noFocus); if (!noFocus) { scope.$on('sm:focus', function () { $timeout(function () { element[0].focus(); }, 10); }); } } }; }]); })();Can you help me to achieve that functionality?