Run plugin after ng-view is loaded

Asked

Viewed 1,029 times

0

I’m using the Locastyle framework for development, so it performs certain functions of plugins like jquery.mask.js and applies in the required elements.

However, sometimes it happens that the plugin runs before the view is loaded, causing it to have no effect on the page.

How can I check if Angular already loaded and view and only then load script?

2 answers

0


You will need to attach a controller to the page and it will execute the script when the view loads completely, that way:

$angular.module('app', ['ngRoute'])
  .config(function ($routeProvider) {
    $routeProvider.when('/', {
      templateUrl:'template/pag1.html',
      controller:'MyController'  //<- Controller anexado
    });
})
  .controller('MyController', function($scope) {
    $scope.$on('$viewContentLoaded', function () {
      //Defina as funções executadas assim que a view seja totalmente carregada
    });
});

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.