0

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;}
7
  • can you add your code? Commented Aug 9, 2017 at 21:51
  • On which condition do you want the function to run? Do you want to run it after a specific time interval or on a particular action by the user? Commented Aug 9, 2017 at 21:51
  • if you want to run functions called when controller init just call then with ng-init ="yourFunction()" Commented Aug 9, 2017 at 21:58
  • i also tried ng-init. Not working Commented Aug 9, 2017 at 22:00
  • <angucomplete-alt id="Te1" ng-init="TemplateE5()" ....... the other attributes. Commented Aug 9, 2017 at 22:02

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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>    

Comments

0
`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="..." />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.