logo
down
shadow

Call function from another Controller in another file AngularJS


Call function from another Controller in another file AngularJS

Content Index :

Call function from another Controller in another file AngularJS
Tag : javascript , By : Jakub Filak
Date : November 23 2020, 01:01 AM

it should still fix some issue Call function from another Controller Angular Js , to @Ved answer I manage to figure it out. Solved.
var app = angular.module('home', [
    'ngRoute',
    'auth'
]);

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Angularjs How do you call a controller method inside a javascript function defined in the html template file?


Tag : angularjs , By : Verbal
Date : March 29 2020, 07:55 AM
will be helpful for those in need I figured it out with help from a friend. Here is the solution:
in the signin.html file add an id to the div at the top. In the script code use that id to get to the scope using jquery (you don't need to use the angular.element()).
<div id="loginwidget">
   <div role="main" id="content" >
       <div id="signIn" >
       </div>
   <div>
 <div>

 <script>
    $.ready('loginwidget_main', function () { 
      loginwidget.load('signin', function () {
           done : success,
           fail : fail  
      });
  });

 function success() {
        var scope = $('#loginwidget').scope();
        scope.test();
 }

 function fail() {alert("failed to login");}

 </script>

AngularJS call common controller function from outside controller


Tag : javascript , By : jbcrail
Date : March 29 2020, 07:55 AM
this will help You could run factory initialization in run method of your angular application. https://docs.angularjs.org/guide/module#module-loading-dependencies E.g.
app.run(['userService', function(userService) {
  userService.get_current_user();
}]);
...
if (data.success == true) {
  root.user = data.user;
}
...
app.controller('myController', ['userService', function(userService) {
   //alert(userService.user);
}]);

Using AngularJs ControllerAs approach, How can I call a function in a parent controller from the child controller?


Tag : angularjs , By : CM.
Date : March 29 2020, 07:55 AM
I hope this helps . To answer your question as clearly as possible, you first must have a bit of background on how the Controller-As syntax actually works.
Using Controller-As does not mean that you are not using $scope. In reality, $scope still exists. Controller-As is shorthand which creates an object on $scope and attaches the properties assigned via this to that object. On the view side, this object is explicitly bound to all the controls. you could still reference $scope.vm.property. However, since $scope is implicit in this scenario, it is not necessary to create a dependency to it.

How to call Angularjs controller function outside the controller in an Ajax call


Tag : javascript , By : TC.
Date : March 29 2020, 07:55 AM
this will help in order to run XMLHttpRequest requests to the server you have many options in angularjs, you dont have to mess with simple javascript and call angular scope to get variables and functions. you can do that either with $http or with services(leave it for now).
i am going to show how you can make the request with $http in native angular.
var app = angular.module('rdExampleApp', ['ui.rdplot']);
app.controller('rdPlotCtrl', function ($scope,$http) {...});
  //show spinner        
 $('.spinner').show();        
 $http.post('dal/addEventHalls.php', {
     data: {'data': $scope.datase}
       })
           .success(function (data) {
              if (data == "null") {
                 //your code if return data empty 
              } else {
                  //your code if return data not empty 
              }
              //hide spinner
              $('.spinner').fadeOut();
          })
           .error(function (data, status, headers, config) {
              console.log('error' + status);
               //hide spinner in case of error
              $('.spinner').fadeOut();
           })

How to call second controller from first controller only after certain function in controller one executed in AngularJs


Tag : angularjs , By : static AG
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I am trying to communicate between two different controllers in AngularJs. The goal I want to achieve is to use the value of variable in first controller once is selected by drop down by user not the default value which i set. but unfortunately second controller used the default value of variable in second controller.
var app = angular.module("myApp",[]);

//controllers declaration
app.controller('myCtrl1',function($scope, $rootScope){
    $scope.selectedOption = "option-1";
    $scope.change = function() {
      $rootScope.$emit('changeName',{selectedOption:$scope.selectedOption});
    }
});

app.controller('myCtrl2',function($scope, $rootScope){
    $scope.selectedOption = "option-2";
    $rootScope.$on('changeName', function(event,data) {
      $scope.selectedOption = data.selectedOption;
    })
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp"> 

<span class="div1" ng-controller="myCtrl1"> 
    <select ng-model="selectedOption" ng-change="change()">
      <option value="option-1">Option 1</option> 
      <option value="option-2">Option 2</option>
      <option value="option-3">Option 3</option>
      <option value="option-4">Option 4</option>
      <option value="option-5">Option 5</option>
    </select>
</span> 

<span class="div2" ng-controller="myCtrl2"> 
    <select ng-model="selectedOption">
      <option value="option-1">Option 1</option> 
      <option value="option-2">Option 2</option>
      <option value="option-3">Option 3</option>
      <option value="option-4">Option 4</option>
      <option value="option-5">Option 5</option>
    </select>
</span> 
 
</body>
Related Posts Related QUESTIONS :
  • How to add obj to to state in my example Redux React
  • Loading "grunt-karma.js" tasks...ERROR >> SyntaxError: Unexpected identifier
  • Why do I get log is not defined
  • get the multiple index of the same string
  • How can I iterate over an Array object by using For IN or FOR OF
  • Launch local executable from web browser
  • How to prepare array of json objects to d3 hierarchical tree structure
  • VueJS - event emitted - show HTML before other calculations
  • Export SASS/SCSS variables to Javascript without exporting them to CSS
  • How to attach an event handler only once continuously
  • How to make button open a link in new tab in JavaScript?
  • Find range from the javascript object
  • How can I use my jQuery code as JavaScript?
  • How to show 5 images in a 2 row slider with bxslider
  • How to convert stream into variables in typescript
  • Three.js custom shader error on Chrome GL_INVALID_OPERATION: Active draw buffers with missing fragment shader outputs
  • My JavaScript doesn't work. How can I solve this problem?
  • Why is this async function is running synchronously?
  • Get updated variable from within react hook before return
  • I want to show all image preview but whenever I upload a new one the old one is gone
  • Would I be able to give access to specific electron APIs safely?
  • Why several clicks fire for each instance of a Class?
  • cant grab value from div using attr()
  • Make web service not accessible by browser?
  • Select DOM elements within template
  • How to customize angular ui-grid row background color?
  • Binding data in two respective $scope in AngularJS, how?
  • react put some props after import class
  • Variable is distributed among same components
  • switch class in jQuery/JavaScript for active/inactive state
  • How To Track Outbound Clicks Using Javascript
  • How to get total seconds elapsed since the beginning of the month?
  • Protractor: Stale element reference at "browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);"
  • Access to an array inside an object
  • Reseting an JavaScript Interval with different value?
  • Learning Angular for the first time - version 2 or 4?
  • Rendering RSS feed (XML) in React with jquery, why do object values parsed from the feed seem empty?
  • Node.js xml2js http.request tag matching
  • applying texture to custom plane geometry in Threejs
  • How do I pass an Event as a function parameter in HTML written inside JavaScript variable?
  • Interface of object parameter with default value and default property
  • Does using try / catch rather than `.catch` observable operator with XHR requests reduce performance?
  • In IE11 background colors not working on printing
  • TypeScript interface signature "(): string"
  • Is synchronous XMLHttpRequest supported in Internet Explorer 10 and 11?
  • Axios function not returning any values with js
  • How to use firestore TIMESTAMP to create time-stamp in JavaScript
  • Instantiate subclass without constructing
  • Outputing a created object in javascript to a server side JSON file
  • Transition the numeric labels in a bar chart
  • createBottomTabNavigator: hide just one tab from the tabBar
  • iife vs simple statement behavior with document.title
  • showDialogPopup Refresh Page after Click
  • Child component does not set the initial value passed from the parent: ReactJS
  • Nodejs javascript added to button not responding
  • Trying to define a promise.all
  • Python GEE to extract featurecollection timeseries from Landsat imageries
  • How to write negative binary number?
  • Unable to set property of individual object
  • Why Named Function Expression itself cannot assign Name to another Value?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com