In AngularJs, how to execute the Js script after the render is complete, angularjsrender

Source: Internet
Author: User

In AngularJs, how to execute the Js script after the render is complete, angularjsrender

AngularJs is Google's open-source front-end JS framework. With AngularJs, we can easily and effectively develop single-page Web applications similar to Gmail. AngularJs, an emerging MVC front-end framework, has the following features: MVC, modularization, automatic two-way data binding, semantic tags, dependency injection, and so on.

What is the difference between AngularJs and Jquery?

The main purpose of Jquery is to simplify Js writing and focus on cross-platform browsers. It is mainly used to operate DOM.
AngularJs focuses on the acquisition and presentation of Html data, and responds to increasingly complex Web application requirements, making it easier to develop a large Web application.

How AngularJs presents pages

AnguarJs provides some enhanced semantic tags (directive) for Html, which are executed after the browser loads the page. For example:

<table id=”leaderBoard”>
          <thead>
              <tr>
                  <th>Id</th>
                  <th>Name</th>
                  <th>Salary</th>
              </tr>
          </thead>
          <tbody>
              <tr ng-repeat="user in users">
                  <td>{{user.Id}}</td>
                  <td>{{user.Name}}</td>
                  <td>{{user.Salary}}</td>
              </tr>
          </tbody>
</table>

The above ng-repeat is a directive, which is equivalent to a for loop. After the page is loaded, AngularJs will traverse the users data object to render (render) the content in this table.

How to execute Js scripts after render is complete

When we use Jquery in combination with AngulraJs, we hope to execute a js script after render finishes table and apply JqTable to this table. In actual development, we often encounter such a requirement, hoping to capture the events that AngularJs finishes page rendering.
To achieve this goal, we need to customize direve VE for the current app:

app.directive('onFinishRenderFilters', function ($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element, attr) {
            if (scope.$last === true) {
                $timeout(function() {
                    scope.$emit('ngRepeatFinished');
                });
            }
        }
    };
});

Then, add the directive where we need to monitor:

<tr ng-repeat="user in users" on-finish-render-filters>
      <td>{{user.Id}}</td>
      <td>{{user.Name}}</td>
      <td>{{user.Salary}}</td>
</tr>

Finally, we need to add the Js script after the render is complete:

$scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
//Here is the JS executed after the table render is completed
var table = $("#leaderBoard").dataTable({
bJQueryUI: true,
"sScrollX": '100%',
};
}; 

 


How to Use angularjs to obtain the focus of a text box

You can write commands.
<! DOCTYPE html>  
Establish an AngularJS Environment

Pay attention to the following key areas,
1. Add ng-app
2. Introduce angularjs.
See angularjs.org/here for details.
<! Doctype html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.