1

So, in two words I want to have an input which is placed inside of another element with ng-if behavior.

There is an input focusing example. It works well. But until I change ng-show to ng-if.

In that case I should change my markup to the following:

<div data-ng-if="showPanel">
    <input type="text" data-ng-focus-on="focusInput" data-ng-model="$parent.inputValue" />
</div>

where ng-focus-on is my directive:

    // ...
    .directive('ngFocusOn', function() {
        return {
            restrict: 'A',
            link: {
                post: function(scope, elem, attr) {
                        scope.$on(attr.ngFocusOn, function(e) {
                            window.setTimeout(function() {
                                elem[0].focus();
                            }, 0);
                        });
                    }
            }
        };
    });

For the focus activation I call the following from my viewmodel:

scope.$broadcast('focusInput');

... but that does not trigger the directive even handler in appropriate scope. It does though, when I am subscribing to parent scope.$parent.$on event, but that does not make my directive universal. I would rather to call $broadcast relatively to appropriate scope, but that's not clear for me, which one.

Community
  • 1
  • 1
Agat
  • 4,577
  • 2
  • 34
  • 62

0 Answers0