dimanche 28 juin 2015

Executing Angular.js-controller method on element shown

How to execute controllers method on element shown. I have a tabs, and i want load data when user open a tab, if i using ng-init, information loads after page loading.

var systemSettingsController = manageApp.controller("SystemSettingsController", [ "$scope", function($scope) { $scope.tab = 1; $scope.initTab = function(tab) { $scope.tab = tab; }; } ]); var emailManagementController = manageApp.controller("EmailManagementController", function($scope, $http) { $scope.smtpServer = ""; $scope.smtpLogin = ""; $scope.smtpPassword = ""; this.init = function() { $http.get("/api/EmailSettings") .then(function(res) { var obj = angular.fromJson(res.data); $scope.smtpServer = obj["Email.SmtpServer"]; $scope.smtpLogin = obj["Email.SenderAddress"]; $scope.smtpPassword = obj["Email.SenderPassword"]; }); }; ...

I want execute method init (EmailManagementController) without using ng-init, and at the moment when this element is displayed on the screen, that is, its display will change to a property different from none.

Aucun commentaire:

Enregistrer un commentaire