Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a submitDetails function inside controller in app.js file and I want to call it from a javascript function. But its throwing error Error: Submit Details is undefined

clickApply: function(e) {
            
            console.log("hi&hello");
            
                    angular.element('#span').scope().submitDetails();
               
            this.hide();
            this.element.trigger('apply.daterangepicker', this);

        }

$rootScope.submitDetails=function()

share|improve this question
    
can you pls elaborate pls add html and js code in a working format – Samuel J Mathew 10 hours ago
    
See This: stackoverflow.com/questions/16709373/… – Jenny 10 hours ago

This can be done as below

JS

  var app = angular.module('myApp', []);

  app.controller('ctrl', function($scope) {
    $scope.sayHello = function() {
      $scope.msg = 'Hello';
    }
  });
  setTimeout(function() {
    var scope = angular.element(document.getElementById("btn")).scope();
    scope.$apply(function() {
      scope.sayHello();
    });
  }, 2000)

HTML

  <div ng-app='myApp'>
    <div ng-controller='ctrl' id='ctrl'>
      {{msg}}
      <button id='btn' ng-click='sayHello()'>
        Go
      </button>
    </div>

  </div>

Hope this will help you Jsfiddle link

share|improve this answer
    
you're mixing vanilla js and angularjs. And you're manipulating DOM from controller – Gonzalo.- 33 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.