Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TextAngular
Message
General information
Forum:
Javascript
Category:
Other
Title:
Miscellaneous
Thread ID:
01604974
Message ID:
01605025
Views:
24
>>
>>Do you know how to find out the current element name (or Id)?
>>
>>I am trying
>>
>> 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)
>>
>>In this directive
>>
>
>Scope is just an object that lets you pass info between the view and controller. The element the directive is operating on is passed right into the link function (assuming that's what you mean). So
>
>
>element.id
>// or 
>element.name
>
No, this didn't work. By looking in the debugger I found the following syntax to work

element[0].attributes["id"].value

------------------------------------------

However, I am still not sure of this directive and not sure I understand its code.

I want to be able to use it on the element by
<input sm-focus ...>
or
<input sm-focus="false" ...>
and in the last case don't set the focus.

Here is my current code
(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?

Thanks again.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform