How to call JavaScript, JQuery, Angular $scope function from Console

When we are using AngularJs for client side development. We are not able to call any $scope function directly from console like we can call any function in Java script and in jQuery.

But some time it’s very necessary to call Angular $scope function for Testing purpose. So, Today I am going to demonstrate some easy tricks to call AngularJs $scope function from console.

Following we have one example of simple AngularJs Page. Having one Java Script, One JQuery and Two AngularJs $scope function

Java Script Function – JsTest()

JQuery Function – JQueryTest()

AngularJs Function -


Now we will call all function from console for this open following program in Google Chrome. And right click anywhere in web page and select “Inspect element”.

It will show you screen like this.



<!DOCTYPE html>
    <title>How to call $scope function from console</title>
    <link rel="stylesheet" href="">
    <script src=""></script>
    <script src="//"></script>
        var app = angular.module("myApp", []);
        app.controller("MyDemoController", function($scope) {
            $scope.message = "How to call $scope function from console";
            $scope.showHello = function() {
                alert("Hello Angular");
            $scope.sum = function(value1, value2) {
                return value1 + value2;
        function JsTest() {
            alert("Js Hello");
        $(document).ready(function() {
            $.fn.JQueryTest = function() {
                alert("JQuery Hello");
    <div ng-app="myApp" ng-controller="MyDemoController" id="myDiv">
        <div id="msg">
            <br />
        <button ng-click="showHello()">Show Hello</button>

Now go into “console” and follow following steps

Call Java Script function from console

For call Java Script function from console we just need write “JsTest()” into console. Like this


Call JQuery function from console

For call JQuery Function from console use JQuery function like this “$().JQueryTest()”. Like this


Call AngularJs $scope function from Console

Now call two AngularJs $Scope function from console.  For call AngularJs functions use following command into console:



#someID – Can be any element’s ID which exists inside ng-controller. But it’s better to use id of element where use using ng-controller. Like we are using myDiv’s ID.


It will show you “Alert Box” having message “Hello AngularJs” Like this


We have another $scope function called “Sum”, Now we will call this using following command


It will return you “200” into console. Like this

You also have option to assign output to variable like we assign output into Sum variable .

Keywords – 

How to call JavaScript Function from console

How to call JQuery Function from console

How to call Angular $Scope Function from console

Next Post »
Thanks for your comment