Call function after instruction is loaded


Shashank

I am working on custom directives for angular 1.6

I want to call a function after loading instructions. Is there a way to do this?

I tried the link function but it seems that the link function is executed before the load instruction.

Any help would be greatly appreciated.

this is my directive code

<pagination total-data= noOfRecords></pagination>
app.directive("pagination", [pagination]);

function pagination() {
    return {
        restrict: 'EA',
        templateUrl: 'template/directives/pagination.html',
        scope: {
            totalData: '=',
        },
        link: dirPaginationControlsLinkFn
    };
}
George

Since you're using AngularJS V1.6, consider this directive as a component:

app.component("pagination", {
    templateUrl: 'template/directives/pagination.html',
    bindings: {
        totalData: '<',
    },
    controller: "paginationCtrl"
})

and use $onChangesand $onInit lifecycle hooks :

app.controller("paginationCtrl", function() {
    this.$onChanges = function(changesObj) {
        if (changesObj.totalData) {
            console.log(changesObj.totalData.currentValue);               
            console.log(changesObj.totalData.previousValue);                 
            console.log(changesObj.totalData.isFirstChange());
        };
    };
    this.$onInit = function() {
        //Code to execute after component loaded
        //...
    });
});

Components are directives constructed in such a way that they can be automatically upgraded to Angular 2+ components. They make the migration to Angular 2+ easier.

For more information, see

Related


Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Cannot call function while instruction is loaded

Shashank I am working on AngularJS custom directives. I'm trying to call a function right after the instruction is loaded. I tried calling the function in the link function but it throws an error due to TypeError : scope.setCurrent is not a function . Here is

Cannot call function while instruction is loaded

Shashank I am working on AngularJS custom directives. I'm trying to call a function right after the instruction is loaded. I tried calling the function in the link function but it throws an error due to TypeError : scope.setCurrent is not a function . Here is

Cannot call function while instruction is loaded

Shashank I am working on AngularJS custom directives. I'm trying to call a function right after the instruction is loaded. I tried calling the function in the link function but it throws an error due to TypeError : scope.setCurrent is not a function . Here is

Cannot call function while instruction is loaded

Shashank I am working on AngularJS custom directives. I'm trying to call a function right after the instruction is loaded. I tried calling the function in the link function but it throws an error due to TypeError : scope.setCurrent is not a function . Here is

Cannot call function while instruction is loaded

Shashank I am working on AngularJS custom directives. I'm trying to call a function right after the instruction is loaded. I tried calling the function in the link function but it throws an error due to TypeError : scope.setCurrent is not a function . Here is

Call the function after the page is loaded

Nitin I am using javascript in my html page. .I've been logging the time spent using the Navigation API. . When I try to find out the total load time (navigationStart-loadEventEnd), I find that loadEventEnd is 0. But also found that the loadEventStart value is

Call the function after the page is loaded

Nitin I am using javascript in my html page. .I've been logging the time spent using the Navigation API. . When I try to find out the total load time (navigationStart-loadEventEnd), I find that loadEventEnd is 0. But also found that the loadEventStart value is

Call function after AJAX is loaded

bull I have jQuery script that helps me to label rows in a table. I also have AJAX functionality to load other data into this table. My idea is that the Picker function is called every time after AJAX is used to tag that data. It works, but is very unstable -

Call function after AJAX is loaded

bull I have jQuery script that helps me to label rows in a table. I also have AJAX functionality to load other data into this table. My idea is that the Picker function is called every time after AJAX is used to tag that data. It works, but is very unstable -

How to call a function after the activity is loaded

kabeth wahra I have an activity using RecyclerView in Android. I tried to call getChildAt(i) on the RecyclerView in OnCreate but it returns null. I tried the same thing in a button click listener created for the test and it returns the item just fine. This mus

jQuery - call function after image is loaded

Simon So I have two functions. One to load the image and the other to resize its container element. Naturally, the image element needs to be loaded before any measurements can be made. It looks like this: var imgEl; loadImage(imgSrc); // only call the below,

call javascript function after script is loaded

Neeraj: I have a html page where i add html dynamically by javascript like below <script type="text/javascript" src="/myapp/htmlCode"></script> I want to call a js function, for example, loadedContent(); once the above script adds dynamic html. Can someone he

Angular - call function after all JS is loaded

User 1857116 I want to call a function when all files (JS) are loaded (because I want to call a function inside one of the files). How do I do this? .state('dashboard', { url: "/dashboard.html", templateUrl: "views/dashboard.html",

Angular - call function after all JS is loaded

User 1857116 I want to call a function when all files (JS) are loaded (because I want to call a function inside one of the files). How do I do this? .state('dashboard', { url: "/dashboard.html", templateUrl: "views/dashboard.html",

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call function angularjs after directive is loaded

Deepak Bandi I have an isolated directive and my controller looks like: app.controller('ZacksController', ['$scope', '$http', 'ngDialog', '$timeout', function($scope, $http, ngDialog, $timeout){ //some code here }]); The HTML in the file looks like this:

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call function angularjs after directive is loaded

Deepak Bandi I have an isolated directive and my controller looks like: app.controller('ZacksController', ['$scope', '$http', 'ngDialog', '$timeout', function($scope, $http, ngDialog, $timeout){ //some code here }]); The HTML in the file looks like this:

Call Javascript function after AJAX is loaded

Laurin Starr I know these questions pop up here. I'm usually not the type to ask questions, but this time I couldn't find a solution by searching. I boiled the problem down to a very simple environment: I have 3 files: Index.php: <html> <html xmlns="http://www

Call function after page is loaded in new tab

Walter After the button is clicked, I need to open some links in a new tab, and more than once the page loads, so I need to programmatically perform some action on this page (e.g. click the appropriate GUI element, etc.). For example, this code should open in

Call function after page is loaded in new tab

Walter After the button is clicked, I need to open some links in a new tab, and after the page is loaded, I need to programmatically perform some actions on this page (eg click on the appropriate GUI element, etc.). For example, this code should open in a new

How to call a function after the activity is loaded

kabeth wahra I have an activity using RecyclerView in Android. I tried to call getChildAt(i) on the RecyclerView in OnCreate but it returns null. I tried the same thing in a button click listener created for the test and it returns the item just fine. This mus

call javascript function after script is loaded

Neeraj: I have a html page where i add html dynamically by javascript like below <script type="text/javascript" src="/myapp/htmlCode"></script> I want to call a js function, for example, loadedContent(); once the above script adds dynamic html. Can someone he

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Angular - call function after all JS is loaded

User 1857116 I want to call a function when all files (JS) are loaded (because I want to call a function inside one of the files). How do I do this? .state('dashboard', { url: "/dashboard.html", templateUrl: "views/dashboard.html",

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi