Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Directives
Message
 
 
À
Tous
Information générale
Forum:
Javascript
Catégorie:
Autre
Titre:
Directives
Divers
Thread ID:
01605023
Message ID:
01605023
Vues:
43
Hi everybody,

I am still not clear how directives work and how to make them optional.

Here is my current code:
(function () {
    'use strict';

    var app = angular.module('ourApp');

    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);
                    });
                }
            }
        };
    }]);
})();
I have sm-focus directive on 2 controls. I want to be able to conditionally show focus.

I tried

sm-focus = "isNew"

I want to be able to use

sm-focus as is and also being able to specify

sm-focus = "isNew" to turn the focus on/off.

Do you know what I should change in that directive to make it work?

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


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform