Devesh Khosla
Devesh Khosla

Reputation: 15

How to call function without ng-click

How we can call function in angularjs without ng-click. I tried ng-show but my function is running again and again. Can any one help me. Basically i want to file function without ng-click.

    <button ng-show="Temp" ng-click="TemplateE5()"> </button>  

i donot want ng-click. it should fire automatically

<angucomplete-alt id="Te1" placeholder="Please type name of template "
    pause="100"  maxlength="20"  input-changed="test"
    selected-object="Temp" local-data="myTemplate"
    search-fields="NAME" title-field="NAME" minlength="0"
    input-class="form-control form-control-small"
    match-class="highlight">
</angucomplete-alt>

<button ng-show="Temp" ng-click="TemplateE5()"> </button> 

controller Side

    $scope.TemplateE5 = function () {
    $scope.users.Time = $scope.Temp.time;
    $scope.users.Paper= $scope.Temp.paper;}

Upvotes: 0

Views: 3562

Answers (3)

Memo 313 MediaSA
Memo 313 MediaSA

Reputation: 79

`app.directive('ngEnter', function () {
return function (scope, element, attrs) {
    element.bind("keydown keypress", function (event) {
        if(event.which === 13) {
            scope.$apply(function (){
                scope.$eval(attrs.ngEnter);
            });

            event.preventDefault();
        }
    });
};

});`

On the web page

<input ng-enter="myFunc()" ng-model="..." />

Upvotes: 0

Devesh Khosla
Devesh Khosla

Reputation: 15

Thank you every one. I used ng-click inside angucomplete-alt it works

<angucomplete-alt id="Te1" ng-click="TemplateE5()"
                  placeholder="Please type name of template "
                  pause="100"  maxlength="20"  input-changed="test"
                  selected-object="Temp" local-data="myTemplate"
                  search-fields="NAME" title-field="NAME" 
                  minlength="0"
                  input-class="form-control form-control-small"
                  match-class="highlight">
</angucomplete-alt>    

Upvotes: 0

Akshay Prabhakar
Akshay Prabhakar

Reputation: 479

You can run it from your controller if you know the ID:

$scope.getSessionsForSpeaker(id);

You can use ng-init to run it when that element loads:

<a ng-init="getSessionsForSpeaker(speaker.id)"></a>

You can also use ng-mouseover if you want to run it when the mouse is over that element

<a ng-mouseover="getSessionsForSpeaker(speaker.id)"></a>

All depends when you want to run it.

Upvotes: 1

Related Questions