Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS. How to call controller function from outside of controller component
    primarykey
    data
    text
    <p>How I can call function defined under controller from any place of web page (outside of controller component)?</p> <p>It works perfectly when I press "get" button. But I need to call it from outside of div controller. The logic is: by default my div is hidden. Somewhere in navigation menu I press a button and it should show() my div and execute "get" function. How I can achieve this?</p> <p>My web page is:</p> <pre><code>&lt;div ng-controller="MyController"&gt; &lt;input type="text" ng-model="data.firstname" required&gt; &lt;input type='text' ng-model="data.lastname" required&gt; &lt;form ng-submit="update()"&gt;&lt;input type="submit" value="update"&gt;&lt;/form&gt; &lt;form ng-submit="get()"&gt;&lt;input type="submit" value="get"&gt;&lt;/form&gt; &lt;/div&gt; </code></pre> <p>My js:</p> <pre><code> function MyController($scope) { // default data and structure $scope.data = { "firstname" : "Nicolas", "lastname" : "Cage" }; $scope.get = function() { $.ajax({ url: "/php/get_data.php?", type: "POST", timeout: 10000, // 10 seconds for getting result, otherwise error. error:function() { alert("Temporary error. Please try again...");}, complete: function(){ $.unblockUI();}, beforeSend: function(){ $.blockUI()}, success: function(data){ json_answer = eval('(' + data + ')'); if (json_answer){ $scope.$apply(function () { $scope.data = json_answer; }); } } }); }; $scope.update = function() { $.ajax({ url: "/php/update_data.php?", type: "POST", data: $scope.data, timeout: 10000, // 10 seconds for getting result, otherwise error. error:function() { alert("Temporary error. Please try again...");}, complete: function(){ $.unblockUI();}, beforeSend: function(){ $.blockUI()}, success: function(data){ } }); }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload