Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make my angular js function to run only one time?

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 338
    Answer it

    I have this plunker.How to make that function to be executed only one time ?

    The code is:
     

    <!DOCTYPE html>
    <html>
    
      <head>
        <script data-require="angular.js@1.1.5" data-semver="1.1.5" src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
        <link rel="stylesheet" href="style.css" />
        <script src="script.js"></script>
      </head>
    
      <body ng-app>
        <div ng-controller="testCtrl">
            <h3>Why does scope function executes X times</h3>
            <div>getLabel executed {{counter}} times</div>
            <div>getLabel result {{getLabel('test')}}</div>
            <div ng-bind="myModel.tmp"></div>
            <div ng-bind="myModel.tmp2"></div>
        </div>
      </body>
    
    </html>

     

    Output:

    Why does scope function executes X times

    getLabel executed 10 times

    getLabel result My label

    Temp value

    Temp value 2

     

    I have executed the code here:

    http://plnkr.co/edit/LLQ7cKs2fEoBwv0C5XPE?p=preview

 2 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: